use of de.danoeh.antennapod.core.util.playback.VideoPlayer in project AntennaPod by AntennaPod.
the class LocalPSMP method getVideoSize.
/**
* Return width and height of the currently playing video as a pair.
*
* @return Width and height as a Pair or null if the video size could not be determined. The method might still
* return an invalid non-null value if the getVideoWidth() and getVideoHeight() methods of the media player return
* invalid values.
*/
@Override
public Pair<Integer, Integer> getVideoSize() {
if (!playerLock.tryLock()) {
// use cached value if lock can't be aquired
return videoSize;
}
Pair<Integer, Integer> res;
if (mediaPlayer == null || playerStatus == PlayerStatus.ERROR || mediaType != MediaType.VIDEO) {
res = null;
} else {
VideoPlayer vp = (VideoPlayer) mediaPlayer;
videoSize = new Pair<>(vp.getVideoWidth(), vp.getVideoHeight());
res = videoSize;
}
playerLock.unlock();
return res;
}
use of de.danoeh.antennapod.core.util.playback.VideoPlayer in project AntennaPod by AntennaPod.
the class LocalPSMP method setMediaPlayerListeners.
private void setMediaPlayerListeners(IPlayer mp) {
if (mp == null || media == null) {
return;
}
if (mp instanceof VideoPlayer) {
if (media.getMediaType() != MediaType.VIDEO) {
Log.w(TAG, "video player, but media type is " + media.getMediaType());
}
VideoPlayer vp = (VideoPlayer) mp;
vp.setOnCompletionListener(videoCompletionListener);
vp.setOnSeekCompleteListener(videoSeekCompleteListener);
vp.setOnErrorListener(videoErrorListener);
vp.setOnBufferingUpdateListener(videoBufferingUpdateListener);
vp.setOnInfoListener(videoInfoListener);
} else if (mp instanceof AudioPlayer) {
if (media.getMediaType() != MediaType.AUDIO) {
Log.w(TAG, "audio player, but media type is " + media.getMediaType());
}
AudioPlayer ap = (AudioPlayer) mp;
ap.setOnCompletionListener(audioCompletionListener);
ap.setOnSeekCompleteListener(audioSeekCompleteListener);
ap.setOnErrorListener(audioErrorListener);
ap.setOnBufferingUpdateListener(audioBufferingUpdateListener);
ap.setOnInfoListener(audioInfoListener);
} else if (mp instanceof ExoPlayerWrapper) {
ExoPlayerWrapper ap = (ExoPlayerWrapper) mp;
ap.setOnCompletionListener(audioCompletionListener);
ap.setOnSeekCompleteListener(audioSeekCompleteListener);
ap.setOnBufferingUpdateListener(audioBufferingUpdateListener);
ap.setOnErrorListener(message -> EventBus.getDefault().postSticky(new PlayerErrorEvent(message)));
ap.setOnInfoListener(audioInfoListener);
} else {
Log.w(TAG, "Unknown media player: " + mp);
}
}
use of de.danoeh.antennapod.core.util.playback.VideoPlayer in project AntennaPod by AntennaPod.
the class LocalPSMP method clearMediaPlayerListeners.
private void clearMediaPlayerListeners() {
if (mediaPlayer instanceof VideoPlayer) {
VideoPlayer vp = (VideoPlayer) mediaPlayer;
vp.setOnCompletionListener(x -> {
});
vp.setOnSeekCompleteListener(x -> {
});
vp.setOnErrorListener((mediaPlayer, i, i1) -> false);
vp.setOnBufferingUpdateListener((mediaPlayer, i) -> {
});
vp.setOnInfoListener((mediaPlayer, i, i1) -> false);
} else if (mediaPlayer instanceof AudioPlayer) {
AudioPlayer ap = (AudioPlayer) mediaPlayer;
ap.setOnCompletionListener(x -> {
});
ap.setOnSeekCompleteListener(x -> {
});
ap.setOnErrorListener((x, y, z) -> false);
ap.setOnBufferingUpdateListener((arg0, percent) -> {
});
ap.setOnInfoListener((arg0, what, extra) -> false);
} else if (mediaPlayer instanceof ExoPlayerWrapper) {
ExoPlayerWrapper ap = (ExoPlayerWrapper) mediaPlayer;
ap.setOnCompletionListener(x -> {
});
ap.setOnSeekCompleteListener(x -> {
});
ap.setOnBufferingUpdateListener((arg0, percent) -> {
});
ap.setOnErrorListener(x -> {
});
ap.setOnInfoListener((arg0, what, extra) -> false);
}
}
use of de.danoeh.antennapod.core.util.playback.VideoPlayer in project AntennaPod by AntennaPod.
the class LocalPSMP method onPrepared.
/**
* Called after media player has been prepared. This method is executed on the caller's thread.
*/
void onPrepared(final boolean startWhenPrepared) {
playerLock.lock();
if (playerStatus != PlayerStatus.PREPARING) {
playerLock.unlock();
throw new IllegalStateException("Player is not in PREPARING state");
}
Log.d(TAG, "Resource prepared");
if (mediaType == MediaType.VIDEO) {
VideoPlayer vp = (VideoPlayer) mediaPlayer;
videoSize = new Pair<>(vp.getVideoWidth(), vp.getVideoHeight());
}
// TODO this call has no effect!
if (media.getPosition() > 0) {
seekToSync(media.getPosition());
}
if (media.getDuration() <= 0) {
Log.d(TAG, "Setting duration of media");
media.setDuration(mediaPlayer.getDuration());
}
setPlayerStatus(PlayerStatus.PREPARED, media);
if (startWhenPrepared) {
resumeSync();
}
playerLock.unlock();
}
use of de.danoeh.antennapod.core.util.playback.VideoPlayer in project AntennaPod by AntennaPod.
the class LocalPSMP method createMediaPlayer.
private IPlayer createMediaPlayer() {
if (mediaPlayer != null) {
mediaPlayer.release();
}
if (media == null || media.getMediaType() == MediaType.VIDEO) {
mediaPlayer = new VideoPlayer();
} else {
mediaPlayer = new AudioPlayer(context);
}
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
return setMediaPlayerListeners(mediaPlayer);
}
Aggregations