// There is a small overhead of actually having to start the media - but
// to mitigate this the media player factory configuration has disabled
// audio and video outputs so there will be no visible/audible sign of
// the media playing
Condition<Integer> parsedCondition = new ParsedCondition(mediaPlayer) {
@Override
protected boolean onBefore() {
// Some media, such as mpg, must be played before all meta data (e.g. duration) is available
mediaPlayer.startMedia(mrl); // "start" waits until the media is playing before returning
mediaPlayer.requestParseMedia(); // asynchronous invocation
return true;
}
@Override
protected void onAfter(Integer result) {
mediaPlayer.stop();
}
};
parsedCondition.await();
// This is functionally equivalent to the simpler synchronous version:
/*
mediaPlayer.startMedia(mrl); // "start" waits until the media is playing before returning
mediaPlayer.parseMedia(); // synchronous invocation