mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 04:43:07 +00:00
implement basics to play videos with ExoPlayer
This commit is contained in:
parent
f45f09056d
commit
75eedf4c29
10 changed files with 291 additions and 108 deletions
|
@ -6,7 +6,7 @@ android {
|
|||
buildToolsVersion "25.0.2"
|
||||
defaultConfig {
|
||||
applicationId "de.nicidienase.chaosflix"
|
||||
minSdkVersion 21
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
<activity android:name=".activities.PlaybackOverlayActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.Leanback"/>
|
||||
<activity android:name=".activities.ExoPlayerActivity"
|
||||
android:theme="@style/Theme.Leanback"/>
|
||||
<service android:name=".network.MediaApiService"/>
|
||||
|
||||
<meta-data android:name="DATABASE" android:value="mediaccc.db" />
|
||||
|
|
|
@ -42,7 +42,6 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
|
|||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
EventsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
fragment.startActivity(i,bundle);
|
||||
|
||||
} else if(item instanceof Event){
|
||||
Event event = (Event) item;
|
||||
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
|
||||
|
|
|
@ -1,10 +1,135 @@
|
|||
package de.nicidienase.chaosflix;
|
||||
|
||||
import android.support.v17.leanback.media.PlaybackControlGlue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.session.MediaController;
|
||||
import android.support.v17.leanback.app.PlaybackControlGlue;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
||||
import de.nicidienase.chaosflix.entities.recording.Recording;
|
||||
import de.nicidienase.chaosflix.entities.streaming.Room;
|
||||
import de.nicidienase.chaosflix.entities.streaming.Stream;
|
||||
import de.nicidienase.chaosflix.fragments.ExoOverlayFragment;
|
||||
|
||||
/**
|
||||
* Created by felix on 26.03.17.
|
||||
*/
|
||||
|
||||
public class PlaybackHelper extends PlaybackControlGlue {
|
||||
|
||||
private static final int[] SEEK_SPEEDS = {2, 4, 8, 16};
|
||||
private static final String TAG = PlaybackHelper.class.getSimpleName();
|
||||
private final Context mContext;
|
||||
private final ExoOverlayFragment mFragment;
|
||||
private Room room;
|
||||
private Stream stream;
|
||||
private Event event;
|
||||
private Recording recording;
|
||||
private MediaController mMediaController;
|
||||
|
||||
public PlaybackHelper(Context context, ExoOverlayFragment fragment, Event event, Recording recording){
|
||||
super(context, fragment,SEEK_SPEEDS);
|
||||
this.mContext = context;
|
||||
this.mFragment = fragment;
|
||||
this.event = event;
|
||||
this.recording = recording;
|
||||
}
|
||||
|
||||
public PlaybackHelper(Context context, ExoOverlayFragment fragment, Room room, Stream stream ){
|
||||
super(context, fragment,SEEK_SPEEDS);
|
||||
this.mContext = context;
|
||||
this.mFragment = fragment;
|
||||
this.room = room;
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValidMedia() {
|
||||
return mediaIsRecording()||mediaIsStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMediaPlaying() {
|
||||
return mFragment.isMediaPlaying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getMediaTitle() {
|
||||
if(mediaIsRecording()){
|
||||
return event.getTitle();
|
||||
}
|
||||
if(mediaIsStream()){
|
||||
return room.getDisplay();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getMediaSubtitle() {
|
||||
if(mediaIsRecording()){
|
||||
return event.getSubtitle();
|
||||
}
|
||||
if(mediaIsStream()){
|
||||
return stream.getDisplay();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMediaDuration() {
|
||||
if(mediaIsRecording()){
|
||||
return event.getLength() * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getMediaArt() {
|
||||
if(mediaIsRecording()){
|
||||
try {
|
||||
return new BitmapDrawable(
|
||||
mContext.getResources(),
|
||||
Glide.with(getContext())
|
||||
.load(event.getThumbUrl())
|
||||
.asBitmap()
|
||||
.into(-1, -1)
|
||||
.get());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSupportedActions() {
|
||||
return ACTION_PLAY_PAUSE | ACTION_FAST_FORWARD | ACTION_REWIND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentSpeedId() {
|
||||
return isMediaPlaying() ? PLAYBACK_SPEED_NORMAL : PLAYBACK_SPEED_PAUSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentPosition() {
|
||||
return mFragment.getCurrentPosition();
|
||||
}
|
||||
|
||||
private boolean mediaIsStream() {
|
||||
return (room != null && stream != null);
|
||||
}
|
||||
private boolean mediaIsRecording(){
|
||||
return (event != null && recording != null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +1,46 @@
|
|||
package de.nicidienase.chaosflix.activities;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v17.leanback.app.PlaybackFragment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
import com.google.android.exoplayer2.ExoPlayerFactory;
|
||||
import com.google.android.exoplayer2.LoadControl;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
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.MediaSource;
|
||||
import com.google.android.exoplayer2.source.dash.DashMediaSource;
|
||||
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
|
||||
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
|
||||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||
import com.google.android.exoplayer2.util.UriUtil;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
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.ExoOverlayFragment;
|
||||
import de.nicidienase.chaosflix.fragments.PlaybackOverlayFragment;
|
||||
|
||||
/**
|
||||
|
@ -29,12 +48,17 @@ import de.nicidienase.chaosflix.fragments.PlaybackOverlayFragment;
|
|||
*/
|
||||
|
||||
public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
||||
implements PlaybackOverlayFragment.OnPlayPauseClickedListener{
|
||||
implements ExoOverlayFragment.PlaybackControlListener{
|
||||
|
||||
@BindView(R.id.videoView)
|
||||
TextureView mTextureView;
|
||||
@BindView(R.id.playback_controls_fragment)
|
||||
View mPlaybackControllFragment;
|
||||
private DefaultBandwidthMeter bandwidthMeter;
|
||||
private SimpleExoPlayer player;
|
||||
private String mUserAgent;
|
||||
|
||||
private static final DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -42,8 +66,19 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
|||
setContentView(R.layout.exoplayback_activity);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
mUserAgent = Util.getUserAgent(this, getResources().getString(R.string.app_name));
|
||||
synchronized (this){
|
||||
if(player == null){
|
||||
setupPlayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupPlayer(){
|
||||
mUserAgent = Util.getUserAgent(this, getResources().getString(R.string.app_name));
|
||||
|
||||
Handler mainHander = new Handler();
|
||||
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
||||
bandwidthMeter = new DefaultBandwidthMeter();
|
||||
TrackSelection.Factory videoTrackSelectionFactory
|
||||
= new AdaptiveTrackSelection.Factory(bandwidthMeter);
|
||||
TrackSelector trackSelector
|
||||
|
@ -51,14 +86,69 @@ public class ExoPlayerActivity extends AbstractServiceConnectedAcitivty
|
|||
|
||||
LoadControl loadControl = new DefaultLoadControl();
|
||||
|
||||
SimpleExoPlayer player =
|
||||
ExoPlayerFactory.newSimpleInstance(this,trackSelector,loadControl);
|
||||
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
|
||||
|
||||
player.setVideoTextureView(mTextureView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentPlayPause(Event event, Recording recording, int position, Boolean playPause) {
|
||||
public void setVideoSource(String source) {
|
||||
synchronized (this){
|
||||
if(player == null){
|
||||
setupPlayer();
|
||||
}
|
||||
}
|
||||
// source = "https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8";
|
||||
MediaSource mediaSource = buildMediaSource(Uri.parse(source), "");
|
||||
player.setPlayWhenReady(true);
|
||||
player.prepare(mediaSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void play() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playPause() {
|
||||
|
||||
}
|
||||
|
||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
|
||||
DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(true);
|
||||
int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
|
||||
: Util.inferContentType("." + overrideExtension);
|
||||
switch (type) {
|
||||
case C.TYPE_SS:
|
||||
return new SsMediaSource(uri, buildDataSourceFactory(false),
|
||||
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), null, null);
|
||||
case C.TYPE_DASH:
|
||||
return new DashMediaSource(uri, buildDataSourceFactory(false),
|
||||
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), null, null);
|
||||
case C.TYPE_HLS:
|
||||
return new HlsMediaSource(uri, mediaDataSourceFactory, null, null);
|
||||
case C.TYPE_OTHER:
|
||||
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
|
||||
null, null);
|
||||
default: {
|
||||
throw new IllegalStateException("Unsupported type: " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
|
||||
return buildDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
|
||||
}
|
||||
|
||||
public DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
|
||||
return new DefaultDataSourceFactory(this, bandwidthMeter,
|
||||
buildHttpDataSourceFactory(bandwidthMeter));
|
||||
}
|
||||
|
||||
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
|
||||
return new DefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,12 +82,12 @@ public class ConferencesBrowseFragment extends BrowseFragment {
|
|||
}
|
||||
}
|
||||
errorFragment.dismiss();
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
setAdapter(mRowsAdapter);
|
||||
});
|
||||
mDisposables.add(disposable2);
|
||||
});
|
||||
mDisposables.add(disposable1);
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
// setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
|
||||
// @Override
|
||||
// public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
|||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v17.leanback.app.DetailsFragment;
|
||||
import android.support.v17.leanback.widget.Action;
|
||||
|
@ -39,6 +40,7 @@ import de.nicidienase.chaosflix.R;
|
|||
import de.nicidienase.chaosflix.activities.AbstractServiceConnectedAcitivty;
|
||||
import de.nicidienase.chaosflix.activities.DetailsActivity;
|
||||
import de.nicidienase.chaosflix.activities.EventDetailsActivity;
|
||||
import de.nicidienase.chaosflix.activities.ExoPlayerActivity;
|
||||
import de.nicidienase.chaosflix.activities.PlaybackOverlayActivity;
|
||||
import de.nicidienase.chaosflix.entities.recording.Conference;
|
||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
||||
|
@ -48,6 +50,7 @@ import de.nicidienase.chaosflix.entities.streaming.LiveConference;
|
|||
import de.nicidienase.chaosflix.entities.streaming.Room;
|
||||
import de.nicidienase.chaosflix.entities.streaming.Stream;
|
||||
import de.nicidienase.chaosflix.entities.streaming.StreamUrl;
|
||||
import de.nicidienase.chaosflix.network.MediaApiService;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
||||
/**
|
||||
|
@ -63,6 +66,8 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
private static final String TAG = EventsDetailsFragment.class.getSimpleName();
|
||||
public static final int FRAGMENT = R.id.details_fragment;
|
||||
private Event mSelectedEvent;
|
||||
private MediaApiService mMediaApiService;
|
||||
private Room mRoom;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -73,7 +78,7 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
BrowseErrorFragment.showErrorFragment(getFragmentManager(),FRAGMENT);
|
||||
mSelectedEvent = getActivity().getIntent()
|
||||
.getParcelableExtra(DetailsActivity.EVENT);
|
||||
Room room = getActivity().getIntent()
|
||||
mRoom = getActivity().getIntent()
|
||||
.getParcelableExtra(DetailsActivity.ROOM);
|
||||
|
||||
final ArrayObjectAdapter adapter = setupDetailsOverviewRowPresenter();
|
||||
|
@ -81,6 +86,7 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
((AbstractServiceConnectedAcitivty)getActivity()).getmApiServiceObservable()
|
||||
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
|
||||
.subscribe(mediaApiService -> {
|
||||
mMediaApiService = mediaApiService;
|
||||
if(mSelectedEvent != null){
|
||||
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(mSelectedEvent);
|
||||
mediaApiService.getEvent(mSelectedEvent.getApiID())
|
||||
|
@ -126,14 +132,14 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
browseErrorFragment.dismiss();
|
||||
});
|
||||
});
|
||||
} else if(room != null){
|
||||
} else if(mRoom != null){
|
||||
mediaApiService.getStreamingConferences()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(liveConferences -> {
|
||||
Room room_ = getRoom(room, liveConferences);
|
||||
if(room_ != null){
|
||||
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(room_);
|
||||
ArrayObjectAdapter actionsAdapter = getStreamActionsAdapter(room_.getStreams());
|
||||
mRoom = getRoom(mRoom, liveConferences);
|
||||
if(mRoom != null){
|
||||
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(mRoom);
|
||||
ArrayObjectAdapter actionsAdapter = getStreamActionsAdapter(mRoom.getStreams());
|
||||
detailsOverviewRow.setActionsAdapter(actionsAdapter);
|
||||
adapter.add(detailsOverviewRow);
|
||||
setAdapter(adapter);
|
||||
|
@ -198,9 +204,15 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
mDetailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
|
||||
@Override
|
||||
public void onActionClicked(Action action) {
|
||||
Intent i = new Intent(getActivity(), PlaybackOverlayActivity.class);
|
||||
// Intent i = new Intent(getActivity(), PlaybackOverlayActivity.class);
|
||||
Intent i = new Intent(getActivity(), ExoPlayerActivity.class);
|
||||
// TODO put stream
|
||||
i.putExtra(DetailsActivity.RECORDING,action.getId());
|
||||
for(Recording r : mSelectedEvent.getRecordings()){
|
||||
if(r.getApiID() == action.getId()){
|
||||
i.putExtra(DetailsActivity.RECORDING,r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
i.putExtra(DetailsActivity.EVENT,mSelectedEvent);
|
||||
getActivity().startActivity(i);
|
||||
}
|
||||
|
@ -250,9 +262,10 @@ public class EventsDetailsFragment extends DetailsFragment {
|
|||
ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter();
|
||||
for(int i = 0; i < recordings.size(); i++){
|
||||
Recording recording = recordings.get(i);
|
||||
if(recording.getMimeType().startsWith("video/") && !recording.getLanguage().contains("-")){
|
||||
if(recording.getMimeType().startsWith("video/")){
|
||||
String quality = recording.isHighQuality() ? "HD" : "SD";
|
||||
actionsAdapter.add(new Action(recording.getApiID(),quality, recording.getLanguage()));
|
||||
String title = quality + " (" + recording.getLanguage() + ")";
|
||||
actionsAdapter.add(new Action(recording.getApiID(), title, recording.getMimeType().substring(6)));
|
||||
}
|
||||
}
|
||||
return actionsAdapter;
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
package de.nicidienase.chaosflix.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
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 android.support.v17.leanback.widget.Row;
|
||||
|
||||
import de.nicidienase.chaosflix.activities.AbstractServiceConnectedAcitivty;
|
||||
import de.nicidienase.chaosflix.PlaybackHelper;
|
||||
import de.nicidienase.chaosflix.activities.DetailsActivity;
|
||||
import de.nicidienase.chaosflix.entities.recording.Event;
|
||||
import de.nicidienase.chaosflix.entities.recording.Recording;
|
||||
|
@ -24,19 +22,19 @@ 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;
|
||||
public class ExoOverlayFragment extends android.support.v17.leanback.app.PlaybackOverlayFragment {
|
||||
|
||||
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;
|
||||
private PlaybackHelper mHelper;
|
||||
private PlaybackControlListener mCallback;
|
||||
|
||||
public interface PlaybackControlListener {
|
||||
void play();
|
||||
void pause();
|
||||
void playPause();
|
||||
void setVideoSource(String source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -45,96 +43,52 @@ public class ExoOverlayFragment extends PlaybackFragment {
|
|||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
mSelectedRecording = intent.getParcelableExtra(DetailsActivity.RECORDING);
|
||||
|
||||
setBackgroundType(PlaybackFragment.BG_LIGHT);
|
||||
setFadingEnabled(false);
|
||||
|
||||
setupRows();
|
||||
addPlaybackControlsRow();
|
||||
addOtherRows();
|
||||
mHelper = new PlaybackHelper(getActivity(),this,mSelectedEvent,mSelectedRecording);
|
||||
|
||||
setAdapter(mRowsAdapter);
|
||||
ArrayObjectAdapter rowsAdapter = setupRows();
|
||||
// rowsAdapter.add(getRelatedItems());
|
||||
setAdapter(rowsAdapter);
|
||||
|
||||
mCallback.setVideoSource(mSelectedRecording.getUrl());
|
||||
}
|
||||
|
||||
private void setupRows() {
|
||||
|
||||
private ArrayObjectAdapter setupRows() {
|
||||
ClassPresenterSelector ps = new ClassPresenterSelector();
|
||||
|
||||
PlaybackControlsRowPresenter playbackControlsRowPresenter;
|
||||
playbackControlsRowPresenter = new PlaybackControlsRowPresenter(
|
||||
new PlaybackOverlayFragment.DescriptionPresenter());
|
||||
playbackControlsRowPresenter.setOnActionClickedListener(new PlaybackControlClickedListener());
|
||||
playbackControlsRowPresenter.setSecondaryActionsHidden(HIDE_MORE_ACTIONS);
|
||||
|
||||
playbackControlsRowPresenter = mHelper.getControlsRowPresenter();
|
||||
ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
|
||||
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
|
||||
mRowsAdapter = new ArrayObjectAdapter(ps);
|
||||
|
||||
|
||||
|
||||
|
||||
return new ArrayObjectAdapter(ps);
|
||||
}
|
||||
|
||||
private void addOtherRows() {
|
||||
private Row getRelatedItems() {
|
||||
// ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
|
||||
// for (Movie movie : mItems) {
|
||||
// listRowAdapter.add(movie);
|
||||
// }
|
||||
// TODO Add related items
|
||||
// HeaderItem header = new HeaderItem(0, getString(R.string.related_movies));
|
||||
// mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
// return new ListRow(header, listRowAdapter);
|
||||
return null;
|
||||
}
|
||||
|
||||
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..
|
||||
public boolean isMediaPlaying() {
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
public int getCurrentPosition() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity context) {
|
||||
super.onAttach(context);
|
||||
if(context instanceof PlaybackControlListener){
|
||||
mCallback = (PlaybackControlListener) context;
|
||||
} else {
|
||||
throw(new RuntimeException("Activity must implement PlaybackControlListener"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package de.nicidienase.chaosflix.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.os.Build;
|
||||
|
@ -113,9 +114,8 @@ public class PlaybackOverlayFragment extends PlaybackFragment {
|
|||
setupRows();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onAttach(Activity context) {
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnPlayPauseClickedListener) {
|
||||
mCallback = (OnPlayPauseClickedListener) context;
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
android:layout_gravity="center"/>
|
||||
|
||||
<fragment
|
||||
android:name="de.nicidienase.chaosflix.fragments.ExoOverlayFragment"
|
||||
android:id="@+id/playback_controls_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:name="de.nicidienase.chaosflix.fragments.ExoOverlayFragment"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue