2012-08-22 62 views
0

我有一個應用程序需要播放.mp4視頻。播放mp4視頻android應用程序

下面是代碼:

try 
{ 
    videoView1 = (VideoView)findViewById(R.id.Video1); 
    video= Uri.parse("android.resource://dr.droid/" + R.raw.burn); 
    mc = new MediaController(this); 
    videoView1.setMediaController(mc); 
    videoView1.setVideoURI(video); 
    videoView1.start(); 
} catch (Exception e) { 
    Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); 
} 

我總是得到一個警報不能播放視頻,但我沒有錯誤。有任何想法嗎?

+0

你會得到什麼警示? – Mus

+0

嘗試[this](http://android-coding.blogspot.in/2011/03/using-videoview-to-play-mp4-from-sdcard.html) – Praveenkumar

+0

無法播放此視頻。 – ljpv14

回答

0

只是做這樣的 -

String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4"; // Instead of this just give your raw folder path. 
/** 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.setVideoPath(SrcPath); 
    myVideoView.setMediaController(new MediaController(this)); 
    myVideoView.requestFocus(); 
    myVideoView.start(); 
} 

希望這會工作。