我有一個應用程序,它的主要目標是播放特定的視頻文件。Android VideoView錯誤1,0
它有時會播放視頻。但其他時候,它給了我這個錯誤:
03-21 14:52:36.181: I/AwesomePlayer(119):
setDataSource_l('/data/data/my.package.name/files/MyMovie.mp4')
03-21 14:52:36.196: W/VideoView(26612): Unable to open content: /data/data/my.package.name/files/MyMovie.mp4
03-21 14:52:36.196: W/VideoView(26612): java.lang.IllegalArgumentException: The surface has been released
03-21 14:52:36.196: W/VideoView(26612): at android.media.MediaPlayer._setVideoSurface(Native Method)
03-21 14:52:36.196: W/VideoView(26612): at android.media.MediaPlayer.setDisplay(MediaPlayer.java:633)
03-21 14:52:36.196: W/VideoView(26612): at android.widget.VideoView.openVideo(VideoView.java:222)
03-21 14:52:36.196: W/VideoView(26612): at android.widget.VideoView.access$2000(VideoView.java:49)
03-21 14:52:36.196: W/VideoView(26612): at android.widget.VideoView$6.surfaceCreated(VideoView.java:465)
03-21 14:52:36.196: W/VideoView(26612): at android.view.SurfaceView.updateWindow(SurfaceView.java:533)
03-21 14:52:36.196: W/VideoView(26612): at android.view.SurfaceView.access$000(SurfaceView.java:81)
03-21 14:52:36.196: W/VideoView(26612): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
03-21 14:52:36.196: W/VideoView(26612): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
03-21 14:52:36.196: W/VideoView(26612): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
03-21 14:52:36.196: W/VideoView(26612): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
03-21 14:52:36.196: W/VideoView(26612): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 14:52:36.196: W/VideoView(26612): at android.os.Looper.loop(Looper.java:137)
03-21 14:52:36.196: W/VideoView(26612): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-21 14:52:36.196: W/VideoView(26612): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 14:52:36.196: W/VideoView(26612): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 14:52:36.196: W/VideoView(26612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-21 14:52:36.196: W/VideoView(26612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-21 14:52:36.196: W/VideoView(26612): at dalvik.system.NativeStart.main(Native Method)
03-21 14:52:36.196: D/VideoView(26612): Error: 1,0
我使用的準備監聽調用這樣開始:
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
mVideoView.start();
}
});
我設置數據源與此:
file = new File(this.getFilesDir() + File.separator + VIDEO_FILE_NAME);
mVideoView.setVideoPath(file.getAbsolutePath());
我知道文件確實存在並且是正確的格式。
我的應用程序能夠從警報觸發器啓動。這似乎只是一個問題,當觸發器觸發並啓動我的應用程序,而設備屏幕關閉(我的應用程序將打開一個喚醒鎖屏)。如果我手動啓動應用程序,或觸發發生在視頻屏幕上播放良好。此錯誤也僅在Galaxy Nexus上發生。我可以在Nexus S上運行完全相同的代碼(以及其他一系列的代碼),並且每次都可以正常運行。
有沒有人知道可能會導致此行爲的Galaxy Nexus或ICS特有的任何內容?有什麼可以嘗試解決的建議嗎?
這個最應該得到由VideoView抽象出來,雖然不應該嗎?我必須做的唯一調用是.prepare(),然後是.start()。開始被聽衆調用,就像你設置的一樣。所以prepare()是我的Activities範圍中唯一被調用的。 – FoamyGuy 2012-04-02 16:18:53
優秀,非常感謝 – braden 2012-05-25 20:52:26