2013-12-16 78 views
3

我想播放mp4 videoin我简单的android videoview。这里是我的代码在Android视频播放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> 

清单看起来像

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) 
以下错误

有没有人脸d一样吗?

请帮助 在此先感谢

+1

固定!!!对于有同样问题的人请注意,Android将只播放H.264压缩视频。一旦我尝试使用上述视频,问题就解决了 – ramesh

回答

0

你的代码看起来不错,我认为这个问题来自于服务器端。我不知道你是如何使用你的服务器的。但请尝试使用您自己的服务器。 请设置一个Apache Web服务器来测试您的本地视频。设置Apache的教程是here

如果你不想使用你自己的服务器,请使用在线mp4链接here,这是我使用的测试文件。

测试此链接的最简单方法是使用Web浏览器打开链接以检查文件是否可访问,只需将URL粘贴到浏览器即可。

如果你已经有了“adb”,你也可以测试你的android端的链接。使用命令:

adb shell am start -a android.intent.action.VIEW -d http://169.228.179.91/username/abc.mp4