Sunday, November 27, 2011

[android-developers] VideoView doesn't start when invisible

I have an AsyncTask, where I hide a video view, start the video playback, and show the video view when the video is playing.

But the video would just not start when the video view is set to invisible, the async task keeps hanging in onBackground. If I comment out this line (or set it to View.VISIBLE), the video starts playing. Why does the video view require a visible surface?

public void walk(final View v) {

   
new AsyncTask() {
       
@Override
       
protected void onPreExecute() {
           
super.onPreExecute();
            mVideoView
.setVisibility(View.INVISIBLE); // this line causes video not to start
            mVideoView
.start();
       
}

       
@Override
       
protected Object doInBackground(Object... objects) {
           
while (!mVideoView.isPlaying()) {}
           
return null;
       
}

       
@Override
       
protected void onPostExecute(Object o) {
           
super.onPostExecute(o);
            mVideoView
.setVisibility(View.VISIBLE);
       
}

   
}.execute();


A bit of background why I'm doing this: 
I try to avoid the well-known issue of the black flash that you usually have when starting a video (or in my case, play one video right after another one, without any gap / black flash):

http://stackoverflow.com/search?q=%5Bandroid%5D+videoview+black

http://stackoverflow.com/search?q=%5Bandroid%5D+video+%5Bmediaplayer%5D+black

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment