mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 04:43:07 +00:00
start implementing our own playback activity and fragment
This commit is contained in:
parent
f4af68bde6
commit
c96907120b
5 changed files with 156 additions and 7 deletions
|
@ -13,9 +13,8 @@ android {
|
|||
}
|
||||
buildTypes {
|
||||
debug {
|
||||
minifyEnabled true
|
||||
minifyEnabled false
|
||||
useProguard false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
release {
|
||||
shrinkResources true
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.os.Handler;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v17.leanback.app.PlaybackFragment;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
import com.google.android.exoplayer2.ExoPlayerFactory;
|
||||
|
@ -19,17 +20,21 @@ import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import de.nicidienase.chaosflix.R;
|
||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
||||
import de.nicidienase.chaosflix.entities.recording.Recording;
|
||||
import de.nicidienase.chaosflix.fragments.PlaybackOverlayFragment;
|
||||
|
||||
/**
|
||||
* Created by felix on 26.03.17.
|
||||
*/
|
||||
|
||||
public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty {
|
||||
public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||
implements PlaybackOverlayFragment.OnPlayPauseClickedListener{
|
||||
|
||||
@BindView(R.id.videoView)
|
||||
TextureView mTextureView;
|
||||
@BindView(R.id.playback_controls_fragment)
|
||||
PlaybackFragment mPlaybackControllFragment;
|
||||
View mPlaybackControllFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -51,4 +56,9 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty {
|
|||
|
||||
player.setVideoTextureView(mTextureView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentPlayPause(Event event, Recording recording, int position, Boolean playPause) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
package de.nicidienase.chaosflix.fragments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v17.leanback.app.PlaybackFragment;
|
||||
import android.support.v17.leanback.widget.Action;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.ClassPresenterSelector;
|
||||
import android.support.v17.leanback.widget.ControlButtonPresenterSelector;
|
||||
import android.support.v17.leanback.widget.ListRow;
|
||||
import android.support.v17.leanback.widget.ListRowPresenter;
|
||||
import android.support.v17.leanback.widget.OnActionClickedListener;
|
||||
import android.support.v17.leanback.widget.PlaybackControlsRow;
|
||||
import android.support.v17.leanback.widget.PlaybackControlsRowPresenter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import de.nicidienase.chaosflix.activities.AbstractServiceConnectedAcitivty;
|
||||
import de.nicidienase.chaosflix.activities.DetailsActivity;
|
||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
||||
import de.nicidienase.chaosflix.entities.recording.Recording;
|
||||
|
||||
/**
|
||||
* Created by felix on 26.03.17.
|
||||
*/
|
||||
|
||||
public class ExoOverlayFragment extends PlaybackFragment {
|
||||
|
||||
private static final boolean HIDE_MORE_ACTIONS = false;
|
||||
|
||||
private Recording mSelectedRecording;
|
||||
private Event mSelectedEvent;
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private PlaybackControlsRow mPlaybackControlsRow;
|
||||
private ArrayObjectAdapter mPrimaryActionsAdapter;
|
||||
private ArrayObjectAdapter mSecondaryActionsAdapter;
|
||||
private PlaybackControlsRow.PlayPauseAction mPlayPauseAction;
|
||||
private PlaybackControlsRow.FastForwardAction mFastForwardAction;
|
||||
private PlaybackControlsRow.RewindAction mRewindAction;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getActivity()
|
||||
.getIntent();
|
||||
mSelectedEvent = intent.getParcelableExtra(DetailsActivity.EVENT);
|
||||
final int mRecordingID = (int) intent.getLongExtra(DetailsActivity.RECORDING, 0);
|
||||
|
||||
((AbstractServiceConnectedAcitivty)getActivity()).getmApiServiceObservable()
|
||||
.subscribe(mediaApiService -> {
|
||||
// mMediaApiService = mediaApiService;
|
||||
|
||||
mediaApiService.getEvent(mSelectedEvent.getApiID())
|
||||
.subscribe(event -> {
|
||||
for(Recording r : event.getRecordings()){
|
||||
if(r.getApiID() == mRecordingID){
|
||||
mSelectedRecording = r;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setBackgroundType(PlaybackFragment.BG_LIGHT);
|
||||
setFadingEnabled(false);
|
||||
|
||||
setupRows();
|
||||
addPlaybackControlsRow();
|
||||
addOtherRows();
|
||||
|
||||
setAdapter(mRowsAdapter);
|
||||
|
||||
}
|
||||
|
||||
private void setupRows() {
|
||||
|
||||
ClassPresenterSelector ps = new ClassPresenterSelector();
|
||||
|
||||
PlaybackControlsRowPresenter playbackControlsRowPresenter;
|
||||
playbackControlsRowPresenter = new PlaybackControlsRowPresenter(
|
||||
new PlaybackOverlayFragment.DescriptionPresenter());
|
||||
playbackControlsRowPresenter.setOnActionClickedListener(new PlaybackControlClickedListener());
|
||||
playbackControlsRowPresenter.setSecondaryActionsHidden(HIDE_MORE_ACTIONS);
|
||||
|
||||
ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
|
||||
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
mRowsAdapter = new ArrayObjectAdapter(ps);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void addOtherRows() {
|
||||
// ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
|
||||
// for (Movie movie : mItems) {
|
||||
// listRowAdapter.add(movie);
|
||||
// }
|
||||
// HeaderItem header = new HeaderItem(0, getString(R.string.related_movies));
|
||||
// mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
|
||||
private void addPlaybackControlsRow() {
|
||||
mPlaybackControlsRow = new PlaybackControlsRow(mSelectedEvent);
|
||||
mRowsAdapter.add(mPlaybackControlsRow);
|
||||
|
||||
// updatePlaybackRow(mCurrentItem);
|
||||
|
||||
ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector();
|
||||
mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
|
||||
mSecondaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
|
||||
mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter);
|
||||
mPlaybackControlsRow.setSecondaryActionsAdapter(mSecondaryActionsAdapter);
|
||||
|
||||
mPlayPauseAction = new PlaybackControlsRow.PlayPauseAction(getActivity());
|
||||
// mRepeatAction = new RepeatAction(getActivity());
|
||||
mFastForwardAction = new PlaybackControlsRow.FastForwardAction(getActivity());
|
||||
mRewindAction = new PlaybackControlsRow.RewindAction(getActivity());
|
||||
|
||||
mPrimaryActionsAdapter.add(new PlaybackControlsRow.RewindAction(getActivity()));
|
||||
mPrimaryActionsAdapter.add(mPlayPauseAction);
|
||||
mPrimaryActionsAdapter.add(new PlaybackControlsRow.FastForwardAction(getActivity()));
|
||||
|
||||
// mSecondaryActionsAdapter.add(mRepeatAction);
|
||||
// The place to toggle audiotracks, subtitles, etc..
|
||||
}
|
||||
|
||||
private class PlaybackControlClickedListener implements OnActionClickedListener {
|
||||
public void onActionClicked(Action action) {
|
||||
if (action.getId() == mPlayPauseAction.getId()) {
|
||||
// TODO play/pause
|
||||
//(mPlayPauseAction.getIndex() == PlaybackControlsRow.PlayPauseAction.PLAY)
|
||||
} else if (action.getId() == mFastForwardAction.getId()) {
|
||||
// TODO fast forward
|
||||
} else if (action.getId() == mRewindAction.getId()) {
|
||||
// TODO rewind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,7 +70,6 @@ public class PlaybackOverlayFragment extends PlaybackFragment {
|
|||
private ArrayObjectAdapter mSecondaryActionsAdapter;
|
||||
|
||||
private PlayPauseAction mPlayPauseAction;
|
||||
// private RepeatAction mRepeatAction;
|
||||
private FastForwardAction mFastForwardAction;
|
||||
private RewindAction mRewindAction;
|
||||
|
||||
|
@ -184,6 +183,7 @@ public class PlaybackOverlayFragment extends PlaybackFragment {
|
|||
mRowsAdapter.add(mPlaybackControlsRow);
|
||||
|
||||
// updatePlaybackRow(mCurrentItem);
|
||||
updateVideoImage(mSelectedEvent.getThumbUrl());
|
||||
|
||||
ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector();
|
||||
mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
|
||||
|
@ -216,7 +216,7 @@ public class PlaybackOverlayFragment extends PlaybackFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void updatePlaybackRow(int index) {
|
||||
private void updatePlaybackRow(Event event) {
|
||||
if (mPlaybackControlsRow.getItem() != null) {
|
||||
Event item = (Event) mPlaybackControlsRow.getItem();
|
||||
item.setTitle(mSelectedEvent.getTitle());
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<fragment
|
||||
android:id="@+id/playback_controls_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:name="de.nicidienase.chaosflix.fragments.ExoOverlayFragment"
|
||||
android:layout_height="match_parent"/>
|
||||
<!--android:name="de.nicidienase.chaosflix.fragments.ExoPlaybackOverlayFragment"-->
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue