2010-07-13 126 views
0

使用:視頻播放只是前5秒

private void play() { 
    VideoView v = (VideoView) findViewById(R.id.videoView); 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.video); 
    mp.setDisplay(v.getHolder()); 
    mp.start(); 
} 

我的視頻播放只是第5秒,並留樣暫停..爲什麼會發生?它與緩衝區有關嗎? (我打本地資源)

-

我嘗試另一個3GP視頻,和同樣的問題發生。

回答

0

工作代碼(也許是一些問題與資源過度使用):

private void play() throws Exception { 
    v = (VideoView) findViewById(R.id.videoView); 
    if (!firstPlay) { 
     mp.release(); 
    } 
    mp = MediaPlayer.create(this, R.raw.video); 
    mp.setDisplay(v.getHolder()); 
    mp.start(); 
    firstPlay = false; 
} 
+0

試回第一個代碼,停下來需要的時間再長一點,我真的認爲是因爲我的許多播放資源過度使用.. – 2010-07-13 14:26:54

0

合併VideoViewMediaPlayer可能不是正確的方法。 VideoView使用自己的MediaPlayeruse VideoView by itselfuse a combination of MediaPlayer and SurfaceView

+0

此外,模擬器上進行視頻回放往往不會很好地工作,除非你有一個非常快的PC。 – CommonsWare 2010-07-13 13:29:55

+0

其實我在這裏有一個非常快的四核。順便說一下,如何使用您的示例的MediaControler播放視頻? – 2010-07-13 14:09:47

+0

@Tom Brito:要播放VideoView樣本,請點擊屏幕的頂部以調出MediaController,或在設置過程結束時向'play()'添加一個調用。要播放「MediaPlayer」示例,您應在啓動應用程序時獲取URL字段,以鍵入要測試的流式視頻剪輯的路徑。 – CommonsWare 2010-07-13 16:03:26