made the local player respect the auto play setting
...also some minor refactoring
This commit is contained in:
parent
14e1abc28e
commit
685491a674
2 changed files with 18 additions and 7 deletions
|
@ -40,14 +40,14 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
final String uri = intent.getDataString();
|
final String uri = parseUriFromIntent(intent);
|
||||||
final VideoSegment[] segments = getSegmentsFromIntent(intent);
|
final VideoSegment[] segments = parseSegmentsFromIntent(intent);
|
||||||
|
|
||||||
localPlayer = new LocalPlayer(this);
|
localPlayer = new LocalPlayer(this);
|
||||||
localPlayer.initPlayer(uri, segments);
|
localPlayer.initialize(uri, segments);
|
||||||
|
|
||||||
final PlayerView playerView = findViewById(R.id.player_view);
|
final PlayerView playerView = findViewById(R.id.player_view);
|
||||||
playerView.setPlayer(localPlayer.getPlayer());
|
playerView.setPlayer(localPlayer.getExoPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,7 +93,11 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve
|
||||||
setKeepScreenOn(false);
|
setKeepScreenOn(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static VideoSegment[] getSegmentsFromIntent(final Intent intent) {
|
private static String parseUriFromIntent(final Intent intent) {
|
||||||
|
return intent.getDataString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VideoSegment[] parseSegmentsFromIntent(final Intent intent) {
|
||||||
final List<VideoSegment> result = new ArrayList<>();
|
final List<VideoSegment> result = new ArrayList<>();
|
||||||
|
|
||||||
final String segmentsJson = intent.getStringExtra("segments");
|
final String segmentsJson = intent.getStringExtra("segments");
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class LocalPlayer implements EventListener {
|
||||||
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
|
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initPlayer(final String uri, final VideoSegment[] segments) {
|
public void initialize(final String uri, final VideoSegment[] segments) {
|
||||||
this.videoSegments = segments;
|
this.videoSegments = segments;
|
||||||
this.progressUpdateReactor = new SerialDisposable();
|
this.progressUpdateReactor = new SerialDisposable();
|
||||||
|
|
||||||
|
@ -62,6 +62,13 @@ public class LocalPlayer implements EventListener {
|
||||||
simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
|
simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
|
||||||
simpleExoPlayer.setHandleAudioBecomingNoisy(true);
|
simpleExoPlayer.setHandleAudioBecomingNoisy(true);
|
||||||
|
|
||||||
|
final String autoPlayStr =
|
||||||
|
mPrefs.getString(context.getString(R.string.autoplay_key), "");
|
||||||
|
final boolean autoPlay =
|
||||||
|
!autoPlayStr.equals(context.getString(R.string.autoplay_never_key));
|
||||||
|
|
||||||
|
simpleExoPlayer.setPlayWhenReady(autoPlay);
|
||||||
|
|
||||||
if (uri == null || uri.length() == 0) {
|
if (uri == null || uri.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +79,7 @@ public class LocalPlayer implements EventListener {
|
||||||
simpleExoPlayer.prepare(videoSource);
|
simpleExoPlayer.prepare(videoSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleExoPlayer getPlayer() {
|
public SimpleExoPlayer getExoPlayer() {
|
||||||
return this.simpleExoPlayer;
|
return this.simpleExoPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue