简体   繁体   English

如何在rawview中显示视频中的mp4视频

[英]How to display mp4 video in videoview from raw folder

I am trying to display a mp4 video from a raw folder. 我试图从原始文件夹显示mp4视频。 The video is supposed to play in a videoview automatically when the app is open. 应用程序打开时,视频应自动在视频视图中播放。 I want the video to begin as soon as the activity is launched (This is the launcher activity). 我希望视频在活动启动后立即开始(这是启动器活动)。 I also want the video to loop and have no sound. 我也希望视频循环播放并且没有声音。 My xml is below. 我的xml在下面。

<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linearLayout" />

This is the code I have. 这是我的代码。

String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";

VideoView mvideo = (VideoView) findViewById(R.id.launcherVideo);

mvideo.setVideoPath(Launcher);

MediaController controller = new MediaController(this);

mvideo.setMediaController(controller);

mvideo.requestFocus();

mvideo.start();

} }

This code currently does not do anything but display a blank screen when I run the app and I don't know why. 此代码当前没有做任何事情,但在运行应用程序时显示空白屏幕,我不知道为什么。 Can anyone help out? 任何人都可以帮忙吗?

I don't see you use this variable, and I don't see how you define Launcher variable. 我没有看到你使用这个变量,我也看不到你如何定义Launcher变量。

String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";

to open video file from raw folder you can do this way: 要从原始文件夹打开视频文件,您可以这样做:

Uri uri = Uri.parse(fileName);
mvideo.setVideoURI(uri);
mvideo.start()

I hope it can help solve your problem 我希望它可以帮助你解决问题

Thanks for the help guys, I figured it out. 感谢帮助人员,我想通了。

VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
    Uri src = Uri.parse("android.resource://com.package/raw/video_name");
    videoView.setVideoURI(src);

    //videoView.setMediaController(new MediaController(this));

    videoView.start();

This worked for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM