android - Calling MediaPlayer.PrepareAsync from VideoView -
i trying implement playlist of videos have smooth transition 1 video next. mediaplayer object has prepareasync() method seem prebuffer video it's ready play. how invoke prepareasync method videoview object? examples found mediaplayer either don't use videoview , seem create surface scratch. or examples use mediaplayer return parameter on videoview eventlisteners seem occur after videoview.play(). have access videoview's mediaplayer before invoking play method can invoke prepareasync() , later the play().
just user1023110 mentioned, videoview wrapper around mediaplayer. diving source code (since docs aren't useful @ all) confirmed internally calls prepareasync() in private method openvideo():
private void openvideo() { if (muri == null || msurfaceholder == null) { // not ready playback yet, try again later return; } // tell music playback service pause // todo: these constants need published somewhere in framework. intent = new intent("com.android.music.musicservicecommand"); i.putextra("command", "pause"); mcontext.sendbroadcast(i); // shouldn't clear target state, because might have // called start() release(false); try { mmediaplayer = new mediaplayer(); if (maudiosession != 0) { mmediaplayer.setaudiosessionid(maudiosession); } else { maudiosession = mmediaplayer.getaudiosessionid(); } mmediaplayer.setonpreparedlistener(mpreparedlistener); mmediaplayer.setonvideosizechangedlistener(msizechangedlistener); mmediaplayer.setoncompletionlistener(mcompletionlistener); mmediaplayer.setonerrorlistener(merrorlistener); mmediaplayer.setoninfolistener(moninfolistener); mmediaplayer.setonbufferingupdatelistener(mbufferingupdatelistener); mcurrentbufferpercentage = 0; mmediaplayer.setdatasource(mcontext, muri, mheaders); mmediaplayer.setdisplay(msurfaceholder); mmediaplayer.setaudiostreamtype(audiomanager.stream_music); mmediaplayer.setscreenonwhileplaying(true); mmediaplayer.prepareasync(); // don't set target state here either, preserve // target state there before. mcurrentstate = state_preparing; attachmediacontroller(); } catch (ioexception ex) { log.w(tag, "unable open content: " + muri, ex); mcurrentstate = state_error; mtargetstate = state_error; merrorlistener.onerror(mmediaplayer, mediaplayer.media_error_unknown, 0); return; } catch (illegalargumentexception ex) { log.w(tag, "unable open content: " + muri, ex); mcurrentstate = state_error; mtargetstate = state_error; merrorlistener.onerror(mmediaplayer, mediaplayer.media_error_unknown, 0); return; } }
Comments
Post a Comment