Android VideoView Error 1,0

匿名 (未验证) 提交于 2019-12-03 08:28:06

问题:

I have an application thats main goal is to play a specific video file.

it plays the video correctly sometimes. But other times it gives me this error:

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 

I am using the prepared listener to call start like this:

mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {     @Override     public void onPrepared(MediaPlayer arg0) {         mVideoView.start();      } }); 

And I set the data source with this:

file = new File(this.getFilesDir() + File.separator + VIDEO_FILE_NAME); mVideoView.setVideoPath(file.getAbsolutePath()); 

I know for certain that the file does exist and is the proper format.

My application has the ability to be launched from an alarm trigger. It seems to only be a problem when the trigger fires and launches my app while the devices screen is turned off(my app will turn the screen on with a wake lock). If I manually launch the app, or the trigger happens with the screen on the video plays fine. This error is also only occuring on the Galaxy Nexus. I can run the exact same code on a Nexus S(as well as a long list of others) and it starts fine every time.

Does anyone know of anything specific to the Galaxy Nexus or ICS that could cause this behavior? And are there any suggestions for what I could try to fix?

回答1:

UThis is connected to your SurfaceView. Make sure you don't touch the SurfaceView after you have called prepare on you MediaPlayer and that it is visible. In your case where you try to wake up the screen make sure that everything happens in the correct order. So preparing the MediaPlayer for playback is the very last thing which your app should do. It could be that the prepare/playback is initiated prior to the app being fully awake, causing the app to attempt to manipulate the SurfaceView.

The follow code example illustrates how to trigger that kind of exception:

   private void setupVideo(String file){       ...       mSurfaceView = (SurfaceView) findViewById(R.id.surface);       mHolder = mSurfaceView.getHolder(); // DON'T TOUCH BEHIND THIS POINT       mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);       mMediaPlayer.setDisplay(mHolder);       mMediaPlayer.setOnPreparedListener(this);       mMediaPlayer.prepare();    }    @Override    public void onPrepared(final MediaPlayer mp) {       mSurfaceView.setVisibility(View.VISIBLE); // THIS WILL CAUSE THE ERROR       mp.start();    } 


回答2:

I had the same problem with an ICS no name tablet.

SurfaceHolder isn't created when setDisplay method is called, which cause:

03-21 14:52:36.196: W/VideoView(26612): java.lang.IllegalArgumentException: The surface has been released 

To fix it, I use:

private void setupVideo(String file){     ...     mMediaPlayer.setOnPreparedListener(this);     mHolder=mSurfaceView.getHolder();     mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);     mHolder.setKeepScreenOn(true);     mHolder.addCallback(new SurfaceHolder.Callback() {         @Override         public void surfaceCreated(SurfaceHolder holder) {             mHolder=holder;             mMediaPlayer.setDisplay(mHolder);             ...             mMediaPlayer.prepare();         }         @Override         public void surfaceDestroyed(SurfaceHolder holder) { ... }         @Override         public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { ... }     }); }  @Override public void onPrepared(final MediaPlayer mp) {     ...     mMediaPlayer.start(); } 


回答3:

I got around this issue with the below implementation.

@Override protected void onPause() {     Log.v("MediaVideo", "onPause");     super.onPause();     this.mVideoView.pause();     this.mVideoView.setVisibility(View.GONE); }  @Override protected void onDestroy() {     Log.v("MediaVideo", "onDestroy");     super.onDestroy(); }  @Override protected void onResume() {     Log.v("MediaVideo", "onResume");     super.onResume();     this.mVideoView.resume(); } 

Override the OnPause and call mVideoView.pause() and the set visibility to GONE. This way I could resolve the "Activity has leaked window" log error issue.



回答4:

Is your Galaxy Nexus by any chance rooted and running the Keyboard Manager app? I saw the exact same stack trace as you when testing my app out and kept noticing the following line in my logcat dumps:

06-26 08:42:49.511 I/ActivityManager(  218): START {flg=0x10050000 cmp=com.ne0fhykLabs.android.utility.km/.TransitionDialog} from pid 11150 

This is the Keyboard Manager app kicking in as soon as the screen orientation changed.

As soon as I disabled the Keyboard Manager service, everything started working again with my video.

As far as I can tell, they were both using the same SurfaceHolder, and when Keyboard Manager was done with it, it was released, causing that exception when the VideoView tried to use it.

In order to get around this, you could try what is mentioned here (the site is in Chinese, but the link is translated). I haven't tried it yet, but hopefully it will work since it's using its own dedicated SurfaceView.



回答5:

Overriding the onpause and onresume callbacks seemed to fix it for me and it's ONLY for the NEXUS Galaxy that has this problem.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!