media player - android mediaplyer seekTo inside onPrepared -
my problem seems happen on android 4.2.2
i go way idle state -> initialized state -> prepareasync() -> , in onprepared seekto called, on android version mediaplayer returns
"attempt seek past end of file: request = {int>0}, durationms = 0"
and start play beginning, there no point catch this, nor listener, write message log, cannot react on that.
what stranger if call mediaplayer.getduration() in onprepared() returns proper value , not 0.
do think mediaplayer bug or there better place call seekto ? or maybe way how know seekto failed ? avoid periodically check current position if smaller desired position , try call seek approach has lot of different problems.
it smooth streaming video content
i'm trying find solution same problem. best i've come far follows.
on 4.2 i've noticed following call backs received:
1) onvideosizechanged() - height , width = 0
2) onprepared()
3) onvideosizechanged() - proper heights , widths
you can't call seekto in (1) player not yet prepared.
as noted, if call seekto in (2) media player generates warning "attempt seek past end of file"
you receive (3) if mediaplayer.start() has been called, @ point can call seekto() successfully.
mediaplayer mmediaplayer = new mediaplayer(); // + initialisation code boolean mvideosizeisset = false; boolean mmediaplayerisprepared = false; public void onprepared(mediaplayer mediaplayer) { log.d(tag, "onprepared called"); mmediaplayerisprepared = true; if (mvideosizeisset) { mmediaplayer.seekto(); } mmediaplayer.start() } public void onvideosizechanged(mediaplayer mp, int width, int height) { log.d(tag, "onvideosizechanged called"); if (width == 0 || height == 0) { log.d(tag, "invalid video width(" + width + ") or height(" + height + ")"); } else { mvideosizeisset = true; if (mmediaplayerisprepared) { mmediaplayer.seekto(); } } }
(i don't use of boolean guards, if @ media player sample provided sdk, similar).
testing across range of devices/os versions, provides generic solution. however, there bug 4.2. call mmediaplayer.start() seems cause first few frames of video start playing before seekto() occurs, barely visible situation, may more visible you. i'm looking hiding surface view in way until receive onseekcomplete() event, isn't ideal.
if has better solution works across os versions i'd love hear it.
Comments
Post a Comment