2013-12-16 77 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