time-光 2022-11-25 17:32 采纳率: 0%
浏览 44
已结题

VideoView 在Fragment中显示无法播放视频!

真诚求解!

问题描述:在mainActivity中正常播放,而在Fragment运行后模拟器弹窗显示视频无法播放。
Fragment代码
package com.example.myapplication.ui.dashboard;

import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.example.myapplication.R;


public class DashboardFragment extends Fragment {
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View root=inflater.inflate(R.layout.fragment_dashboard,
                container, false);
        VideoView videoView=root.findViewById(R.id.videoView);
        videoView.setVideoURI(Uri.parse("android:resource://" +
                "com.example.graduation_project/ui/knowledgeFragment/"+R.raw.cognition));
        MediaController mediaController=new MediaController(getContext());
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
        return root;
    }
}

Fragment(XML)代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.dashboard.DashboardFragment">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <VideoView
            android:id="@+id/videoView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

报错内容
I/zygote: Do partial code cache collection, code=28KB, data=30KB
    After code cache collection, code=27KB, data=30KB
    Increasing code cache capacity to 128KB
W/MediaPlayer: Couldn't open android:resource://com.example.graduation_project/ui/knowledgeFragment/2131755008: java.io.FileNotFoundException: No content provider: android:resource://com.example.graduation_project/ui/knowledgeFragment/2131755008
E/MediaPlayerNative: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
D/VideoView: Error: 1,-2147483648
I/zygote: Do partial code cache collection, code=44KB, data=54KB
I/zygote: After code cache collection, code=44KB, data=54KB
    Increasing code cache capacity to 256KB
I/zygote: JIT allocated 56KB for compiled code of void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/zygote: Do full code cache collection, code=103KB, data=74KB
    After code cache collection, code=78KB, data=45KB
D/EGL_emulation: eglMakeCurrent: 0x9e705120: ver 2 0 (tinfo 0x9e703260)
I/chatty: uid=10084(u0_a84) RenderThread identical 2 lines
D/EGL_emulation: eglMakeCurrent: 0x9e705120: ver 2 0 (tinfo 0x9e703260)
D/EGL_emulation: eglMakeCurrent: 0x9e705120: ver 2 0 (tinfo 0x9e703260)


  • 写回答

2条回答 默认 最新

  • 码上就疯 2022-11-25 17:53
    关注

    报错不是提示文件找不到吗

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月3日
  • 创建了问题 11月25日

悬赏问题

  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,