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
Added ExoPlayer #2655
Merged
Merged
Added ExoPlayer #2655
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9cf32a2
Added ExoPlayer
ByteHamster 7e61de3
Added streaming support
ByteHamster 06dab67
Fixed some warnings
ByteHamster d50dcac
Added ExoPlayer setting
ByteHamster df8f900
Cleanup
ByteHamster e4f7d65
Variable for exoplayer version
ByteHamster 6d3fc04
Merge branch 'develop' into exo-player
ByteHamster 8c6f40b
Fixed miniplayer position after start
ByteHamster 8b72f35
Merge branch 'develop' into exo-player
ByteHamster c977e70
Removed duplicate String
ByteHamster 2bc3ca7
Merge branch 'develop' into exo-player
ByteHamster 9020687
Added ExoPlayer to about section
ByteHamster 532d822
Merge branch 'develop' into exo-player
ByteHamster 920f061
Fixed build
ByteHamster 83a9df2
Merge branch 'develop' into exo-player
ByteHamster 3d1646c
Merge branch 'develop' into exo-player
ByteHamster a9d9a5a
Added Exoplayer to new method
ByteHamster 6266210
Player names are not translatable
ByteHamster c2184cf
Merge branch 'develop' into exo-player
ByteHamster File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
package de.danoeh.antennapod.core.service.playback; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.view.SurfaceHolder; | ||
import com.google.android.exoplayer2.C; | ||
import com.google.android.exoplayer2.DefaultLoadControl; | ||
import com.google.android.exoplayer2.DefaultRenderersFactory; | ||
import com.google.android.exoplayer2.ExoPlaybackException; | ||
import com.google.android.exoplayer2.ExoPlayerFactory; | ||
import com.google.android.exoplayer2.PlaybackParameters; | ||
import com.google.android.exoplayer2.Player; | ||
import com.google.android.exoplayer2.SeekParameters; | ||
import com.google.android.exoplayer2.SimpleExoPlayer; | ||
import com.google.android.exoplayer2.Timeline; | ||
import com.google.android.exoplayer2.audio.AudioAttributes; | ||
import com.google.android.exoplayer2.source.ExtractorMediaSource; | ||
import com.google.android.exoplayer2.source.MediaSource; | ||
import com.google.android.exoplayer2.source.TrackGroupArray; | ||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; | ||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; | ||
import com.google.android.exoplayer2.upstream.DataSource; | ||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; | ||
import com.google.android.exoplayer2.util.Util; | ||
import de.danoeh.antennapod.core.util.playback.IPlayer; | ||
import org.antennapod.audio.MediaPlayer; | ||
|
||
|
||
public class ExoPlayerWrapper implements IPlayer { | ||
private final Context mContext; | ||
private SimpleExoPlayer mExoPlayer; | ||
private MediaSource mediaSource; | ||
private MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener; | ||
private MediaPlayer.OnCompletionListener audioCompletionListener; | ||
private MediaPlayer.OnErrorListener audioErrorListener; | ||
|
||
ExoPlayerWrapper(Context context) { | ||
mContext = context; | ||
mExoPlayer = createPlayer(); | ||
} | ||
|
||
private SimpleExoPlayer createPlayer() { | ||
SimpleExoPlayer p = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(mContext), | ||
new DefaultTrackSelector(), new DefaultLoadControl()); | ||
p.setSeekParameters(SeekParameters.PREVIOUS_SYNC); | ||
p.addListener(new Player.EventListener() { | ||
@Override | ||
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { | ||
|
||
} | ||
|
||
@Override | ||
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { | ||
|
||
} | ||
|
||
@Override | ||
public void onLoadingChanged(boolean isLoading) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { | ||
if (playbackState == Player.STATE_ENDED) { | ||
audioCompletionListener.onCompletion(null); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRepeatModeChanged(int repeatMode) { | ||
|
||
} | ||
|
||
@Override | ||
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPlayerError(ExoPlaybackException error) { | ||
audioErrorListener.onError(null, 0, 0); | ||
} | ||
|
||
@Override | ||
public void onPositionDiscontinuity(int reason) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { | ||
|
||
} | ||
|
||
@Override | ||
public void onSeekProcessed() { | ||
audioSeekCompleteListener.onSeekComplete(null); | ||
} | ||
}); | ||
return p; | ||
} | ||
|
||
@Override | ||
public boolean canSetSpeed() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean canDownmix() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getCurrentPosition() { | ||
return (int) mExoPlayer.getCurrentPosition(); | ||
} | ||
|
||
@Override | ||
public float getCurrentSpeedMultiplier() { | ||
return mExoPlayer.getPlaybackParameters().speed; | ||
} | ||
|
||
@Override | ||
public int getDuration() { | ||
if (mExoPlayer.getDuration() == C.TIME_UNSET) { | ||
return PlaybackServiceMediaPlayer.INVALID_TIME; | ||
} | ||
return (int) mExoPlayer.getDuration(); | ||
} | ||
|
||
@Override | ||
public boolean isPlaying() { | ||
return mExoPlayer.getPlayWhenReady(); | ||
} | ||
|
||
@Override | ||
public void pause() { | ||
mExoPlayer.setPlayWhenReady(false); | ||
} | ||
|
||
@Override | ||
public void prepare() throws IllegalStateException { | ||
mExoPlayer.prepare(mediaSource); | ||
} | ||
|
||
@Override | ||
public void release() { | ||
if (mExoPlayer != null) { | ||
mExoPlayer.release(); | ||
} | ||
audioSeekCompleteListener = null; | ||
audioCompletionListener = null; | ||
audioErrorListener = null; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
mExoPlayer.release(); | ||
mExoPlayer = createPlayer(); | ||
} | ||
|
||
@Override | ||
public void seekTo(int i) throws IllegalStateException { | ||
mExoPlayer.seekTo(i); | ||
} | ||
|
||
@Override | ||
public void setAudioStreamType(int i) { | ||
AudioAttributes a = mExoPlayer.getAudioAttributes(); | ||
AudioAttributes.Builder b = new AudioAttributes.Builder(); | ||
b.setContentType(i); | ||
b.setFlags(a.flags); | ||
b.setUsage(a.usage); | ||
mExoPlayer.setAudioAttributes(b.build()); | ||
} | ||
|
||
@Override | ||
public void setDataSource(String s) throws IllegalArgumentException, IllegalStateException { | ||
DataSource.Factory dataSourceFactory = | ||
new DefaultDataSourceFactory(mContext, Util.getUserAgent(mContext, mContext.getPackageName()), null); | ||
ExtractorMediaSource.Factory f = new ExtractorMediaSource.Factory(dataSourceFactory); | ||
mediaSource = f.createMediaSource(Uri.parse(s)); | ||
} | ||
|
||
@Override | ||
public void setDisplay(SurfaceHolder sh) { | ||
mExoPlayer.setVideoSurfaceHolder(sh); | ||
} | ||
|
||
@Override | ||
public void setPlaybackSpeed(float v) { | ||
PlaybackParameters params = mExoPlayer.getPlaybackParameters(); | ||
mExoPlayer.setPlaybackParameters(new PlaybackParameters(v, params.pitch)); | ||
} | ||
|
||
@Override | ||
public void setDownmix(boolean b) { | ||
|
||
} | ||
|
||
@Override | ||
public void setVolume(float v, float v1) { | ||
mExoPlayer.setVolume(v); | ||
} | ||
|
||
@Override | ||
public void setWakeMode(Context context, int i) { | ||
|
||
} | ||
|
||
@Override | ||
public void start() { | ||
mExoPlayer.setPlayWhenReady(true); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
mExoPlayer.stop(); | ||
} | ||
|
||
void setOnCompletionListener(MediaPlayer.OnCompletionListener audioCompletionListener) { | ||
this.audioCompletionListener = audioCompletionListener; | ||
} | ||
|
||
void setOnSeekCompleteListener(MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener) { | ||
this.audioSeekCompleteListener = audioSeekCompleteListener; | ||
} | ||
|
||
void setOnErrorListener(MediaPlayer.OnErrorListener audioErrorListener) { | ||
this.audioErrorListener = audioErrorListener; | ||
} | ||
|
||
int getVideoWidth() { | ||
if (mExoPlayer.getVideoFormat() == null) { | ||
return 0; | ||
} | ||
return mExoPlayer.getVideoFormat().width; | ||
} | ||
|
||
int getVideoHeight() { | ||
if (mExoPlayer.getVideoFormat() == null) { | ||
return 0; | ||
} | ||
return mExoPlayer.getVideoFormat().height; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this has already been merged, but I just wanted to say that the sonic player test still depends on this.
https://github.com/AntennaPod/AntennaPod/blob/develop/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java#L62
That being said, I just started looking into this codebase this evening and as of right now all tests are still failing for me, so I'm not sure whether I should make a PR for that. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently working on fixing the tests in #2870 ;)