我正尝试在我的drawable-mdpi文件夹中创建和制作视频(d1)的应用程序。 我希望在用户启动应用程序时播放此视频。在Android应用程序中播放项目中的视频
这是我第一次尝试这种类型,所以不知道该怎么做。
我MainActivity.Java onCreate方法代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView vv = (VideoView)this.findViewById(R.id.vv01);
String uriString = "android.resource://" + getPackageName() + "/" + R.drawable.d1;
vv.setVideoURI(Uri.parse(uriString));
vv.start();
}
我activity_main.xml中的文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/vv01"
android:contentDescription="@string/app_name"
/>
</RelativeLayout>
我不知道如果我使用的URI路径字符串正确与否。请建议如何实现它,因为它目前不工作。 另外,如果可能的话,请建议如何包含播放/暂停按钮和重新指向新视频的“下一个视频”按钮。
您的视频文件是可绘制文件夹? –
是的,这是为什么它不起作用? – Harry
将行文件夹放入res文件夹并将视频文件放入行文件夹中。 –