Search in sources :

Example 1 with AudioPlayer

use of de.danoeh.antennapod.core.util.playback.AudioPlayer 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);
    }
}
Also used : VideoPlayer(de.danoeh.antennapod.core.util.playback.VideoPlayer) PlayerErrorEvent(de.danoeh.antennapod.event.PlayerErrorEvent) AudioPlayer(de.danoeh.antennapod.core.util.playback.AudioPlayer)

Example 2 with AudioPlayer

use of de.danoeh.antennapod.core.util.playback.AudioPlayer 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);
    }
}
Also used : VideoPlayer(de.danoeh.antennapod.core.util.playback.VideoPlayer) Context(android.content.Context) PlayerErrorEvent(de.danoeh.antennapod.event.PlayerErrorEvent) SpeedChangedEvent(de.danoeh.antennapod.event.playback.SpeedChangedEvent) AudioFocusRequestCompat(androidx.media.AudioFocusRequestCompat) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NonNull(androidx.annotation.NonNull) VolumeAdaptionSetting(de.danoeh.antennapod.model.feed.VolumeAdaptionSetting) Pair(android.util.Pair) BufferUpdateEvent(de.danoeh.antennapod.event.playback.BufferUpdateEvent) FutureTask(java.util.concurrent.FutureTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IPlayer(de.danoeh.antennapod.core.util.playback.IPlayer) AudioAttributesCompat(androidx.media.AudioAttributesCompat) MediaPlayer(org.antennapod.audio.MediaPlayer) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) AudioManager(android.media.AudioManager) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) UiModeManager(android.app.UiModeManager) PowerManager(android.os.PowerManager) Future(java.util.concurrent.Future) FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) VideoPlayer(de.danoeh.antennapod.core.util.playback.VideoPlayer) RewindAfterPauseUtils(de.danoeh.antennapod.playback.base.RewindAfterPauseUtils) TelephonyManager(android.telephony.TelephonyManager) EventBus(org.greenrobot.eventbus.EventBus) AudioPlayer(de.danoeh.antennapod.core.util.playback.AudioPlayer) AudioManagerCompat(androidx.media.AudioManagerCompat) SurfaceHolder(android.view.SurfaceHolder) Log(android.util.Log) MediaPlayerError(de.danoeh.antennapod.core.util.playback.MediaPlayerError) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) MediaType(de.danoeh.antennapod.model.playback.MediaType) ReentrantLock(java.util.concurrent.locks.ReentrantLock) PlaybackSpeedUtils(de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils) Playable(de.danoeh.antennapod.model.playback.Playable) IOException(java.io.IOException) File(java.io.File) PlayerStatus(de.danoeh.antennapod.playback.base.PlayerStatus) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) Configuration(android.content.res.Configuration) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) AudioPlayer(de.danoeh.antennapod.core.util.playback.AudioPlayer)

Example 3 with AudioPlayer

use of de.danoeh.antennapod.core.util.playback.AudioPlayer 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);
}
Also used : VideoPlayer(de.danoeh.antennapod.core.util.playback.VideoPlayer) AudioPlayer(de.danoeh.antennapod.core.util.playback.AudioPlayer)

Aggregations

AudioPlayer (de.danoeh.antennapod.core.util.playback.AudioPlayer)3 VideoPlayer (de.danoeh.antennapod.core.util.playback.VideoPlayer)3 PlayerErrorEvent (de.danoeh.antennapod.event.PlayerErrorEvent)2 UiModeManager (android.app.UiModeManager)1 Context (android.content.Context)1 Configuration (android.content.res.Configuration)1 AudioManager (android.media.AudioManager)1 PowerManager (android.os.PowerManager)1 TelephonyManager (android.telephony.TelephonyManager)1 Log (android.util.Log)1 Pair (android.util.Pair)1 SurfaceHolder (android.view.SurfaceHolder)1 NonNull (androidx.annotation.NonNull)1 AudioAttributesCompat (androidx.media.AudioAttributesCompat)1 AudioFocusRequestCompat (androidx.media.AudioFocusRequestCompat)1 AudioManagerCompat (androidx.media.AudioManagerCompat)1 PlaybackSpeedUtils (de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils)1 UserPreferences (de.danoeh.antennapod.core.preferences.UserPreferences)1 IPlayer (de.danoeh.antennapod.core.util.playback.IPlayer)1 MediaPlayerError (de.danoeh.antennapod.core.util.playback.MediaPlayerError)1