我正在尝试在我的简单 android VideoView 中播放 mp4 视频。这是我的代码
VideoView videoView;
videoView = (VideoView) findViewById(R.id.videoViewa);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
//URI either from net
Uri video = Uri.parse("http://www.fieldandrurallife.tv/videos/Benltey%20Mulsanne.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
我的布局看起来像
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<VideoView
android:id="@+id/videoViewa"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="match_parent" />
</RelativeLayout>
list 看起来像
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
当我尝试启动应用程序时出现以下错误
Couldn't open file on client side, trying server side
error (1, -1004)
有人遇到过同样的情况吗?
请帮忙 提前致谢
最佳答案
您的代码看起来不错,我认为问题出在服务器端。我不知道你是如何使用你的服务器的。但是尝试使用您自己的服务器。 请设置 Apache 网络服务器来测试您的本地视频。设置 Apache 的教程是 here
如果您不想使用自己的服务器,请使用在线 mp4 链接 here ,这是我使用的测试文件。
测试此链接最简单的方法是使用网络浏览器打开链接以检查文件是否可访问,只需将 URL 复制粘贴到浏览器即可。
如果您已经拥有“adb”,您也可以在您的 android 端测试该链接。使用命令:
adb shell am start -a android.intent.action.VIEW -d http://169.228.179.91/username/abc.mp4
关于android - 在android videoview中播放一个mp4文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20609811/