-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add boundary time observer similar to iOS AVPlayer SDK #95
Comments
This is a great idea, will be added to the next version :) |
Thanks Mario - that's brilliant! Along a similar line is the ability to play clips within a media file. iOS and UWP both support this with the native players, but not Android afraid unfortunately. |
Yes setting the start and end point is not explicitly implemented as a feature but will easily be achievable with the Cue API in the upcoming version: // Start at the 5 second mark
final int clipStartTime = 5000;
// End at the 10 second mark
final int clipEndTime = 10000;
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// Seek to the start time when player is ready
mp.seekTo(clipStartTime);
// Add a cue marker for the end time
mp.addCue(clipEndTime);
mp.setOnCueListener(new MediaPlayer.OnCueListener() {
@Override
public void onCue(MediaPlayer mp, Cue cue) {
// Once the end time cue is reached we stop playback.
// We don't need to use the cue object in this case because we know that we only
// added a single cue so when the event is triggered we can be sure that this is
// the end time cue.
mp.stop();
}
});
// Start playback
mp.start();
}
}); |
Working with multiple cues could look like this: Cue clipEndTimeCue = mp.addCue(clipEndTime);
Cue someOtherCue = mp.addCue(someOtherTime);
mp.setOnCueListener(new MediaPlayer.OnCueListener() {
@Override
public void onCue(MediaPlayer mp, Cue cue) {
// We make use of the Cue object returned by addCue
if (cue == clipEndTimeCue) {
mp.stop();
} else {
// Do something else with other cues
...
}
}
}); Or like this: Object clipEndTimeMarkerData = ...;
mp.addCue(clipEndTime, clipEndTimeMetadata);
mp.addCue(someOtherTime);
mp.setOnCueListener(new MediaPlayer.OnCueListener() {
@Override
public void onCue(MediaPlayer mp, Cue cue) {
// We make use of the optional data carried by the Cue object
if (cue.getData() == clipEndTimeMarkerData) {
mp.stop();
} else {
// Do something else with other cues
...
}
}
}); |
Released in v4.4.0. |
@protyposis Brilliant work! We can't wait to test this out next week. |
We love MediaPlayerExtended and use it extensively in our app!
Recently, we have a new use case where we wish to play clips or segments from full-length media files.
One of the challenges however, is detecting when the end of the clip occurs.
MediaPlayer has OnCompletionListener but this only fires at the end of full-length playback.
What is the feasibility of adding something similar to addBoundaryTimeObserver on iOS?
Apple SDK Documentation
ie. While MPE is decoding frames, you can set a time point at which you want the player to fire an event. You could then use this to listen for the end time for a video clip and respond accordingly.
The text was updated successfully, but these errors were encountered: