2012-10-06 64 views
1

我在本地服務器中有一個視頻文件。我餵我的android代碼與視頻文件的URL。我在Htdocs文件夾的視頻文件夾中有視頻文件。我在stackoverflow上查找了相同的問題,但找不到解決方案。請幫忙。下面的代碼..對不起,無法播放視頻

public class WatchActivity extends Activity { 

String SrcPath = "http://localhost/video/Coldplay - In My Place.mp4"; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview); 
     myVideoView.setVideoURI(Uri.parse(SrcPath)); 
     myVideoView.setMediaController(new MediaController(this)); 
     myVideoView.requestFocus(); 
     myVideoView.start(); 
    } 
} 

這裏是這個

10-06 12:02:11.473: D/MediaPlayer(332): Couldn't open file on client side, trying server side 
10-06 12:02:11.523: E/MediaPlayer(332): error (1, -111) 
10-06 12:02:11.723: E/MediaPlayer(332): Error (1,-111) 
10-06 12:02:11.723: D/VideoView(332): Error: 1,-111 
10-06 12:02:12.083: D/dalvikvm(332): GC_EXTERNAL_ALLOC freed 65K, 52% free 2609K/5379K, external 1813K/2137K, paused 50ms 

回答

1

首先logcat的你的鏈接是錯誤的。試用10.0.2.2而不是localhost

請嘗試使用.3gp視頻文件。

請嘗試下面的鏈接。 http://daily3gp.com/vids/747.3gp

在清單文件中添加Internet權限。

<uses-permission android:name="android.permission.INTERNET"/> 

編輯:

VideoView videoView = (VideoView)this.findViewById(R.id.videoView); 
MediaController mc = new MediaController(this); 
mc.setAnchorView(videoView); 
mc.setMediaPlayer(videoView); 
videoView.setMediaController(mc); 
videoView.setVideoURI(Uri.parse("http://hermes.sprc.samsung.pl/widget/tmp/testh.3gp")); 

videoView.requestFocus(); 
videoView.start(); 
+0

我試過'10.0.2.2',而不是'localhost',沒有運氣。我有相同視頻的3gp版本。在發佈問題之前,我已經嘗試過。 – ashi

+0

@ashi你有沒有在Android清單文件中添加Internet權限? –

+0

我剛纔添加了它。但仍然不起作用 – ashi