mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 12:53:08 +00:00
add controls
This commit is contained in:
parent
8c1d56729e
commit
04b86c872e
3 changed files with 45 additions and 17 deletions
|
@ -4,9 +4,9 @@ import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v17.leanback.app.PlaybackFragment;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.TextureView;
|
import android.util.Log;
|
||||||
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
@ -15,7 +15,6 @@ import com.google.android.exoplayer2.ExoPlayerFactory;
|
||||||
import com.google.android.exoplayer2.LoadControl;
|
import com.google.android.exoplayer2.LoadControl;
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
|
|
||||||
import com.google.android.exoplayer2.source.ExtractorMediaSource;
|
import com.google.android.exoplayer2.source.ExtractorMediaSource;
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.source.dash.DashMediaSource;
|
import com.google.android.exoplayer2.source.dash.DashMediaSource;
|
||||||
|
@ -32,16 +31,12 @@ import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
import com.google.android.exoplayer2.util.UriUtil;
|
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import de.nicidienase.chaosflix.R;
|
import de.nicidienase.chaosflix.R;
|
||||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
|
||||||
import de.nicidienase.chaosflix.entities.recording.Recording;
|
|
||||||
import de.nicidienase.chaosflix.fragments.ExoOverlayFragment;
|
import de.nicidienase.chaosflix.fragments.ExoOverlayFragment;
|
||||||
import de.nicidienase.chaosflix.fragments.PlaybackOverlayFragment;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by felix on 26.03.17.
|
* Created by felix on 26.03.17.
|
||||||
|
@ -50,8 +45,9 @@ import de.nicidienase.chaosflix.fragments.PlaybackOverlayFragment;
|
||||||
public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||||
implements ExoOverlayFragment.PlaybackControlListener{
|
implements ExoOverlayFragment.PlaybackControlListener{
|
||||||
|
|
||||||
|
private static final String TAG = ExoPlayerActivity.class.getSimpleName();
|
||||||
@BindView(R.id.videoView)
|
@BindView(R.id.videoView)
|
||||||
TextureView mTextureView;
|
SurfaceView mSurfaceView;
|
||||||
@BindView(R.id.playback_controls_fragment)
|
@BindView(R.id.playback_controls_fragment)
|
||||||
View mPlaybackControllFragment;
|
View mPlaybackControllFragment;
|
||||||
private DefaultBandwidthMeter bandwidthMeter;
|
private DefaultBandwidthMeter bandwidthMeter;
|
||||||
|
@ -59,6 +55,7 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||||
private String mUserAgent;
|
private String mUserAgent;
|
||||||
|
|
||||||
private static final DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
|
private static final DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
|
||||||
|
private Handler mainHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
@ -74,10 +71,16 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
pause();
|
||||||
|
}
|
||||||
|
|
||||||
private void setupPlayer(){
|
private void setupPlayer(){
|
||||||
mUserAgent = Util.getUserAgent(this, getResources().getString(R.string.app_name));
|
mUserAgent = Util.getUserAgent(this, getResources().getString(R.string.app_name));
|
||||||
|
|
||||||
Handler mainHander = new Handler();
|
mainHandler = new Handler();
|
||||||
bandwidthMeter = new DefaultBandwidthMeter();
|
bandwidthMeter = new DefaultBandwidthMeter();
|
||||||
TrackSelection.Factory videoTrackSelectionFactory
|
TrackSelection.Factory videoTrackSelectionFactory
|
||||||
= new AdaptiveTrackSelection.Factory(bandwidthMeter);
|
= new AdaptiveTrackSelection.Factory(bandwidthMeter);
|
||||||
|
@ -88,11 +91,12 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||||
|
|
||||||
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
|
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
|
||||||
|
|
||||||
player.setVideoTextureView(mTextureView);
|
player.setVideoSurfaceView(mSurfaceView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVideoSource(String source) {
|
public void setVideoSource(String source) {
|
||||||
|
Log.d(TAG,"Source: " + source);
|
||||||
synchronized (this){
|
synchronized (this){
|
||||||
if(player == null){
|
if(player == null){
|
||||||
setupPlayer();
|
setupPlayer();
|
||||||
|
@ -106,16 +110,33 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void play() {
|
public void play() {
|
||||||
|
player.setPlayWhenReady(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pause() {
|
public void pause() {
|
||||||
|
player.setPlayWhenReady(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playPause() {
|
public void playPause() {
|
||||||
|
player.setPlayWhenReady(!player.getPlayWhenReady());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void seekTo(int sec) {
|
||||||
|
player.seekTo(sec * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void skipForward(int sec){
|
||||||
|
player.seekTo(player.getCurrentPosition()+(sec*1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void skipBackward(int sec){
|
||||||
|
player.seekTo(player.getCurrentPosition()-(sec*1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
|
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
|
||||||
|
@ -125,15 +146,15 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case C.TYPE_SS:
|
case C.TYPE_SS:
|
||||||
return new SsMediaSource(uri, buildDataSourceFactory(false),
|
return new SsMediaSource(uri, buildDataSourceFactory(false),
|
||||||
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), null, null);
|
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
|
||||||
case C.TYPE_DASH:
|
case C.TYPE_DASH:
|
||||||
return new DashMediaSource(uri, buildDataSourceFactory(false),
|
return new DashMediaSource(uri, buildDataSourceFactory(false),
|
||||||
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), null, null);
|
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
|
||||||
case C.TYPE_HLS:
|
case C.TYPE_HLS:
|
||||||
return new HlsMediaSource(uri, mediaDataSourceFactory, null, null);
|
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
|
||||||
case C.TYPE_OTHER:
|
case C.TYPE_OTHER:
|
||||||
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
|
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
|
||||||
null, null);
|
mainHandler, null);
|
||||||
default: {
|
default: {
|
||||||
throw new IllegalStateException("Unsupported type: " + type);
|
throw new IllegalStateException("Unsupported type: " + type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,9 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
|
||||||
void pause();
|
void pause();
|
||||||
void playPause();
|
void playPause();
|
||||||
void setVideoSource(String source);
|
void setVideoSource(String source);
|
||||||
|
void skipForward(int sec);
|
||||||
|
void skipBackward(int sec);
|
||||||
|
void seekTo(int sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,8 +56,6 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
|
||||||
ArrayObjectAdapter rowsAdapter = setupRows();
|
ArrayObjectAdapter rowsAdapter = setupRows();
|
||||||
// rowsAdapter.add(getRelatedItems());
|
// rowsAdapter.add(getRelatedItems());
|
||||||
setAdapter(rowsAdapter);
|
setAdapter(rowsAdapter);
|
||||||
|
|
||||||
mCallback.setVideoSource(mSelectedRecording.getUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayObjectAdapter setupRows() {
|
private ArrayObjectAdapter setupRows() {
|
||||||
|
@ -82,6 +83,12 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
mCallback.setVideoSource(mSelectedRecording.getRecordingUrl());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity context) {
|
public void onAttach(Activity context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextureView
|
<SurfaceView
|
||||||
android:id="@+id/videoView"
|
android:id="@+id/videoView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
Loading…
Reference in a new issue