2012-04-15 39 views
2

當我播放視頻時,使用prepareAsync(),然後在視頻準備好時調用start(),從start()調用到視頻實際需要大約250ms開始玩。這是怎麼回事,還是有趣的事情發生在這裏?請注意,該視頻位於原始目錄中。在我的活動的OnCreate我:Android MediaPlayer:準備好的視頻需要250ms才能開始播放

private VideoView vv; 
private MediaPlayer mp = new MediaPlayer(); 
vv = (VideoView)findViewById(R.id.vv); 
vv.getHolder().addCallback(this); 
mp.reset(); 
mp.setDisplay(vv.getHolder()); 
mp.setDataSource(this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.moviename)); 
Log.d(TAG,"video is preparing"); 
mp.prepareAsync(); 

於是就有了聽衆:

@Override 
public void onPrepared(MediaPlayer arg0) { 
    Log.d(TAG, "video is prepared"); 
    mp.start(); 
} 

其實我的代碼是比這更復雜。用戶點擊一個按鈕來播放視頻,也可以選擇不同的視頻。我有一個圖像隱藏視頻,並從mp.start()一定數量的ms我拉這張圖片,揭示視頻。在我的設備上,我必須將其設置爲250毫秒,以便可靠地不透露視頻以外的內容(即黑色或前一視頻播放的最後一幀)。

我想知道的是,您是否可以從我的logcat中發現某件事情與此不符。我很好奇那些沒有標題爲ButtonBookActivity的消息。他們是否正常?這些是mp4s。請注意,在這種情況下準備視頻只需要120ms。

04-15 13:30:05.600: D/ButtonBookActivity(1238): video is reset 
04-15 13:30:05.620: I/NuCachedSource2(83): ERROR_END_OF_STREAM 
04-15 13:30:05.630: D/AwesomePlayer(83): Failed to open file, all profile flags have to set through setprop method. 
04-15 13:30:05.630: I/MPEG4Extractor(83): NON-QT MODE DECIDED 
04-15 13:30:05.640: I/SampleTable(83): There are reordered frames present. 
04-15 13:30:05.640: D/ButtonBookActivity(1238): video is preparing 
04-15 13:30:05.640: I/OMXCodec(83): [OMX.Nvidia.h264.decode] AVC profile = 77 (Main), level = 32 
04-15 13:30:05.640: I/OMXCodec(83): [OMX.Nvidia.h264.decode] video dimensions are 800 x 1280 
04-15 13:30:05.640: I/OMXCodec(83): [OMX.Nvidia.h264.decode] Crop rect is 800 x 1280 @ (0, 0) 
04-15 13:30:05.760: D/ButtonBookActivity(1238): video is prepared 
04-15 13:30:06.540: D/ButtonBookActivity(1238): touch event 
04-15 13:30:06.540: D/ButtonBookActivity(1238): button clicked 
04-15 13:30:06.550: D/ButtonBookActivity(1238): calling playmovie in onTouch callback 
04-15 13:30:06.550: D/ButtonBookActivity(1238): playing movie 
04-15 13:30:06.550: D/ButtonBookActivity(1238): delaying movie reveal 
04-15 13:30:06.560: D/NvOsDebugPrintf(83): Allocating new output: 800x1280 (x 12) 
04-15 13:30:06.570: I/OMXCodec(83): [OMX.Nvidia.h264.decode] video dimensions are 800 x 1280 
04-15 13:30:06.570: I/OMXCodec(83): [OMX.Nvidia.h264.decode] Crop rect is 800 x 1280 @ (0, 0) 
04-15 13:30:06.620: D/ButtonBookActivity(1238): touch event 
04-15 13:30:06.620: D/ButtonBookActivity(1238): ignoring touch event 
04-15 13:30:06.770: V/NvAudioALSA(83): open called for devices 00000002 in mode 0... 
04-15 13:30:06.770: V/NvAudioALSA(83): getAlsaDeviceName::devices 0x2 IsVoiceCallDevice 0 devName music 
04-15 13:30:06.770: V/NvAudioALSA(83): Reset buffer size to 4096 and latency to 92879 
04-15 13:30:06.770: V/NvAudioALSA(83): Set PLAYBACK PCM format to S16_LE (Signed 16 bit Little Endian) 
04-15 13:30:06.770: V/NvAudioALSA(83): Using 2 channels for PLAYBACK. 
04-15 13:30:06.770: V/NvAudioALSA(83): Set PLAYBACK sample rate to 44100 HZ 
04-15 13:30:06.770: V/NvAudioALSA(83): Buffer size: 4096 
04-15 13:30:06.770: V/NvAudioALSA(83): Period size: 1024 
04-15 13:30:06.770: V/NvAudioALSA(83): Latency: 92879 
04-15 13:30:06.770: V/NvAudioALSA(83): Period Time: 23219 
04-15 13:30:06.770: V/NvAudioALSA(83): Periods: 4 
04-15 13:30:07.060: V/NvAudioALSA(83): Initialized ALSA PLAYBACK device music 
04-15 13:30:09.550: D/ButtonBookActivity(1238): video completed 
+1

我沒有你的答案,但我也對你可能提出的任何答案感興趣。我收到類似的消息,試圖在WebView

回答

1

This可能與android音頻延遲問題有關。 對於音頻文件的start()調用需要一些時間,然後纔會有實際的揚聲器發出聲音。也許這也適用於視頻和媒體播放器在顯示任何視頻幀之前需要一段時間。

所以可能沒有什麼可以做的。

相關問題