handle streams and recordings to start playback

This commit is contained in:
Felix 2017-03-30 22:52:06 +02:00
parent 5209ccfb8f
commit 1e66ad3719
6 changed files with 124 additions and 57 deletions

View file

@ -45,6 +45,7 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
} else if(item instanceof Event){ } else if(item instanceof Event){
Event event = (Event) item; Event event = (Event) item;
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class); Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
i.putExtra(DetailsActivity.TYPE,DetailsActivity.TYPE_RECORDING);
i.putExtra(DetailsActivity.EVENT,event); i.putExtra(DetailsActivity.EVENT,event);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
fragment.getActivity(), fragment.getActivity(),
@ -55,6 +56,7 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
if(item instanceof Room){ if(item instanceof Room){
Room room = (Room) item; Room room = (Room) item;
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class); Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
i.putExtra(DetailsActivity.TYPE,DetailsActivity.TYPE_STREAM);
i.putExtra(DetailsActivity.ROOM,room); i.putExtra(DetailsActivity.ROOM,room);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
fragment.getActivity(), fragment.getActivity(),

View file

@ -15,6 +15,7 @@ import de.nicidienase.chaosflix.entities.recording.Event;
import de.nicidienase.chaosflix.entities.recording.Recording; import de.nicidienase.chaosflix.entities.recording.Recording;
import de.nicidienase.chaosflix.entities.streaming.Room; import de.nicidienase.chaosflix.entities.streaming.Room;
import de.nicidienase.chaosflix.entities.streaming.Stream; import de.nicidienase.chaosflix.entities.streaming.Stream;
import de.nicidienase.chaosflix.entities.streaming.StreamUrl;
import de.nicidienase.chaosflix.fragments.ExoOverlayFragment; import de.nicidienase.chaosflix.fragments.ExoOverlayFragment;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
@ -34,7 +35,7 @@ public class PlaybackHelper extends PlaybackControlGlue {
private final ExoOverlayFragment mFragment; private final ExoOverlayFragment mFragment;
private BitmapDrawable mDrawable = null; private BitmapDrawable mDrawable = null;
private Room room; private Room room;
private Stream stream; private StreamUrl stream;
private Event event; private Event event;
private Recording recording; private Recording recording;
private Runnable mUpdateProgressRunnable; private Runnable mUpdateProgressRunnable;
@ -47,6 +48,9 @@ public class PlaybackHelper extends PlaybackControlGlue {
this.event = event; this.event = event;
this.recording = recording; this.recording = recording;
controlListener = (ExoOverlayFragment.PlaybackControlListener) context;
if(event != null){
Observable.fromCallable(() -> Observable.fromCallable(() ->
new BitmapDrawable( new BitmapDrawable(
mContext.getResources(), mContext.getResources(),
@ -60,9 +64,10 @@ public class PlaybackHelper extends PlaybackControlGlue {
.doOnError(Throwable::printStackTrace) .doOnError(Throwable::printStackTrace)
.subscribe(bitmapDrawable -> mDrawable = bitmapDrawable); .subscribe(bitmapDrawable -> mDrawable = bitmapDrawable);
} }
}
public PlaybackHelper(Context context, ExoOverlayFragment fragment, Room room, Stream stream ){ public PlaybackHelper(Context context, ExoOverlayFragment fragment, Room room, StreamUrl stream ){
super(context, fragment,SEEK_SPEEDS); super(context, SEEK_SPEEDS);
this.mContext = context; this.mContext = context;
this.mFragment = fragment; this.mFragment = fragment;
this.room = room; this.room = room;

View file

@ -27,7 +27,12 @@ public class DetailsActivity extends AbstractServiceConnectedAcitivty {
public static final String SHARED_ELEMENT_NAME = "hero"; public static final String SHARED_ELEMENT_NAME = "hero";
public static final String EVENT = "event"; public static final String EVENT = "event";
public static final String ROOM = "room"; public static final String ROOM = "room";
public static final String STREAM_URL = "stream_url";
public static final String RECORDING = "recording"; public static final String RECORDING = "recording";
public static final String TYPE = "event_type";
public static final int TYPE_RECORDING = 0;
public static final int TYPE_STREAM = 1;
/** /**
* Called when the activity is first created. * Called when the activity is first created.

View file

@ -14,7 +14,8 @@ import java.util.List;
public class Event extends SugarRecord implements Parcelable, Comparable<Event> { public class Event extends SugarRecord implements Parcelable, Comparable<Event> {
int parentConferenceID; @SerializedName("conference_id")
int conferenceId;
String guid; String guid;
String title; String title;
String subtitle; String subtitle;
@ -42,6 +43,7 @@ public class Event extends SugarRecord implements Parcelable, Comparable<Event>
String conferenceUrl; String conferenceUrl;
List<Recording> recordings; List<Recording> recordings;
protected Event(Parcel in) { protected Event(Parcel in) {
guid = in.readString(); guid = in.readString();
title = in.readString(); title = in.readString();
@ -127,16 +129,16 @@ public class Event extends SugarRecord implements Parcelable, Comparable<Event>
return Integer.parseInt(strings[strings.length-1]); return Integer.parseInt(strings[strings.length-1]);
} }
public long getParentConferenceID() { public long getConferenceId() {
if(parentConferenceID == 0){ if(conferenceId == 0){
String[] split = conferenceUrl.split("/"); String[] split = conferenceUrl.split("/");
parentConferenceID = Integer.parseInt(split[split.length-1]); conferenceId = Integer.parseInt(split[split.length-1]);
} }
return parentConferenceID; return conferenceId;
} }
public void setParentConferenceID(int parentConferenceID) { public void setConferenceId(int conferenceId) {
this.parentConferenceID = parentConferenceID; this.conferenceId = conferenceId;
} }
public String getGuid() { public String getGuid() {

View file

@ -4,7 +4,6 @@ import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v17.leanback.app.DetailsFragment; import android.support.v17.leanback.app.DetailsFragment;
import android.support.v17.leanback.widget.Action; import android.support.v17.leanback.widget.Action;
@ -17,7 +16,6 @@ import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElement
import android.support.v17.leanback.widget.HeaderItem; import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ListRow; import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter; import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnActionClickedListener;
import android.support.v17.leanback.widget.Presenter; import android.support.v17.leanback.widget.Presenter;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -41,7 +39,6 @@ import de.nicidienase.chaosflix.activities.AbstractServiceConnectedAcitivty;
import de.nicidienase.chaosflix.activities.DetailsActivity; import de.nicidienase.chaosflix.activities.DetailsActivity;
import de.nicidienase.chaosflix.activities.EventDetailsActivity; import de.nicidienase.chaosflix.activities.EventDetailsActivity;
import de.nicidienase.chaosflix.activities.ExoPlayerActivity; 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.Conference;
import de.nicidienase.chaosflix.entities.recording.Event; import de.nicidienase.chaosflix.entities.recording.Event;
import de.nicidienase.chaosflix.entities.recording.Recording; import de.nicidienase.chaosflix.entities.recording.Recording;
@ -68,6 +65,8 @@ public class EventsDetailsFragment extends DetailsFragment {
private Event mSelectedEvent; private Event mSelectedEvent;
private MediaApiService mMediaApiService; private MediaApiService mMediaApiService;
private Room mRoom; private Room mRoom;
private int eventType;
private ArrayList<StreamUrl> streamUrlList;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -76,10 +75,15 @@ public class EventsDetailsFragment extends DetailsFragment {
final BrowseErrorFragment browseErrorFragment = final BrowseErrorFragment browseErrorFragment =
BrowseErrorFragment.showErrorFragment(getFragmentManager(),FRAGMENT); BrowseErrorFragment.showErrorFragment(getFragmentManager(),FRAGMENT);
eventType = getActivity().getIntent().getIntExtra(DetailsActivity.TYPE, -1);
if(eventType == DetailsActivity.TYPE_RECORDING){
mSelectedEvent = getActivity().getIntent() mSelectedEvent = getActivity().getIntent()
.getParcelableExtra(DetailsActivity.EVENT); .getParcelableExtra(DetailsActivity.EVENT);
} else if(eventType == DetailsActivity.TYPE_STREAM){
mRoom = getActivity().getIntent() mRoom = getActivity().getIntent()
.getParcelableExtra(DetailsActivity.ROOM); .getParcelableExtra(DetailsActivity.ROOM);
}
final ArrayObjectAdapter adapter = setupDetailsOverviewRowPresenter(); final ArrayObjectAdapter adapter = setupDetailsOverviewRowPresenter();
@ -87,7 +91,7 @@ public class EventsDetailsFragment extends DetailsFragment {
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage())) .doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
.subscribe(mediaApiService -> { .subscribe(mediaApiService -> {
mMediaApiService = mediaApiService; mMediaApiService = mediaApiService;
if(mSelectedEvent != null){ if(eventType == DetailsActivity.TYPE_RECORDING){
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(mSelectedEvent); final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(mSelectedEvent);
mediaApiService.getEvent(mSelectedEvent.getApiID()) mediaApiService.getEvent(mSelectedEvent.getApiID())
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage())) .doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
@ -98,7 +102,7 @@ public class EventsDetailsFragment extends DetailsFragment {
detailsOverviewRow.setActionsAdapter(recordingActionsAdapter); detailsOverviewRow.setActionsAdapter(recordingActionsAdapter);
adapter.add(detailsOverviewRow); adapter.add(detailsOverviewRow);
mediaApiService.getConference( mediaApiService.getConference(
mSelectedEvent.getParentConferenceID()) mSelectedEvent.getConferenceId())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(conference -> { .subscribe(conference -> {
String tag = null; String tag = null;
@ -132,7 +136,7 @@ public class EventsDetailsFragment extends DetailsFragment {
browseErrorFragment.dismiss(); browseErrorFragment.dismiss();
}); });
}); });
} else if(mRoom != null){ } else if(eventType == DetailsActivity.TYPE_STREAM){
mediaApiService.getStreamingConferences() mediaApiService.getStreamingConferences()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(liveConferences -> { .subscribe(liveConferences -> {
@ -201,21 +205,27 @@ public class EventsDetailsFragment extends DetailsFragment {
mDetailsPresenter.setListener(helper); mDetailsPresenter.setListener(helper);
prepareEntranceTransition(); prepareEntranceTransition();
mDetailsPresenter.setOnActionClickedListener(new OnActionClickedListener() { mDetailsPresenter.setOnActionClickedListener(action -> {
@Override
public void onActionClicked(Action action) {
// Intent i = new Intent(getActivity(), PlaybackOverlayActivity.class);
Intent i = new Intent(getActivity(), ExoPlayerActivity.class); Intent i = new Intent(getActivity(), ExoPlayerActivity.class);
// TODO put stream i.putExtra(DetailsActivity.TYPE,eventType);
if(eventType == DetailsActivity.TYPE_RECORDING){
i.putExtra(DetailsActivity.EVENT,mSelectedEvent);
for(Recording r : mSelectedEvent.getRecordings()){ for(Recording r : mSelectedEvent.getRecordings()){
if(r.getApiID() == action.getId()){ if(r.getApiID() == action.getId()){
i.putExtra(DetailsActivity.RECORDING,r); i.putExtra(DetailsActivity.RECORDING,r);
break; break;
} }
} }
i.putExtra(DetailsActivity.EVENT,mSelectedEvent); } else if(eventType == DetailsActivity.TYPE_STREAM){
getActivity().startActivity(i); i.putExtra(DetailsActivity.ROOM,mRoom);
StreamUrl streamUrl = getStreamUrlForActionId((int) action.getId());
if(streamUrl != null){
i.putExtra(DetailsActivity.STREAM_URL, streamUrl);
} else {
// TODO handle missing Stream
} }
}
getActivity().startActivity(i);
}); });
ClassPresenterSelector mPresenterSelector = new ClassPresenterSelector(); ClassPresenterSelector mPresenterSelector = new ClassPresenterSelector();
@ -260,6 +270,7 @@ public class EventsDetailsFragment extends DetailsFragment {
private ArrayObjectAdapter getRecordingActionsAdapter(List<Recording> recordings) { private ArrayObjectAdapter getRecordingActionsAdapter(List<Recording> recordings) {
ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter(); ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter();
if(recordings != null){
for(int i = 0; i < recordings.size(); i++){ for(int i = 0; i < recordings.size(); i++){
Recording recording = recordings.get(i); Recording recording = recordings.get(i);
if(recording.getMimeType().startsWith("video/")){ if(recording.getMimeType().startsWith("video/")){
@ -268,21 +279,33 @@ public class EventsDetailsFragment extends DetailsFragment {
actionsAdapter.add(new Action(recording.getApiID(), title, recording.getMimeType().substring(6))); actionsAdapter.add(new Action(recording.getApiID(), title, recording.getMimeType().substring(6)));
} }
} }
}
return actionsAdapter; return actionsAdapter;
} }
private ArrayObjectAdapter getStreamActionsAdapter(List<Stream> streams){ private ArrayObjectAdapter getStreamActionsAdapter(List<Stream> streams){
ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter(); ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter();
streamUrlList = new ArrayList<StreamUrl>();
for(Stream s: streams){ for(Stream s: streams){
if(s.getType().equals("video")) if(s.getType().equals("video"))
for(String key :s.getUrls().keySet()){ for(String key :s.getUrls().keySet()){
StreamUrl url = s.getUrls().get(key); StreamUrl url = s.getUrls().get(key);
actionsAdapter.add(new Action(0,s.getDisplay(), url.getDisplay())); int index = streamUrlList.size();
streamUrlList.add(url);
actionsAdapter.add(new Action(index,s.getDisplay(), url.getDisplay()));
} }
} }
return actionsAdapter; return actionsAdapter;
} }
private StreamUrl getStreamUrlForActionId(int actionId){
if(streamUrlList != null && streamUrlList.size() > actionId){
return streamUrlList.get(actionId);
} else {
return null;
}
}
static class EventDetailsOverviewLogoPresenter extends DetailsOverviewLogoPresenter { static class EventDetailsOverviewLogoPresenter extends DetailsOverviewLogoPresenter {
static class ViewHolder extends DetailsOverviewLogoPresenter.ViewHolder { static class ViewHolder extends DetailsOverviewLogoPresenter.ViewHolder {
public ViewHolder(View view) { public ViewHolder(View view) {

View file

@ -6,16 +6,21 @@ import android.os.Bundle;
import android.support.v17.leanback.app.PlaybackFragment; import android.support.v17.leanback.app.PlaybackFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter; import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ClassPresenterSelector; import android.support.v17.leanback.widget.ClassPresenterSelector;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ListRow; import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter; import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.PlaybackControlsRow; import android.support.v17.leanback.widget.PlaybackControlsRow;
import android.support.v17.leanback.widget.PlaybackControlsRowPresenter; import android.support.v17.leanback.widget.PlaybackControlsRowPresenter;
import android.support.v17.leanback.widget.Row; import android.support.v17.leanback.widget.Row;
import de.nicidienase.chaosflix.CardPresenter;
import de.nicidienase.chaosflix.PlaybackHelper; import de.nicidienase.chaosflix.PlaybackHelper;
import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.activities.DetailsActivity; import de.nicidienase.chaosflix.activities.DetailsActivity;
import de.nicidienase.chaosflix.entities.recording.Event; import de.nicidienase.chaosflix.entities.recording.Event;
import de.nicidienase.chaosflix.entities.recording.Recording; import de.nicidienase.chaosflix.entities.recording.Recording;
import de.nicidienase.chaosflix.entities.streaming.Room;
import de.nicidienase.chaosflix.entities.streaming.StreamUrl;
/** /**
* Created by felix on 26.03.17. * Created by felix on 26.03.17.
@ -25,9 +30,13 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
private Recording mSelectedRecording; private Recording mSelectedRecording;
private Event mSelectedEvent; private Event mSelectedEvent;
private Room mSelectedRoom;
private PlaybackHelper mHelper; private PlaybackHelper mHelper;
private PlaybackControlListener mCallback; private PlaybackControlListener mCallback;
private ArrayObjectAdapter mRowsAdapter; private ArrayObjectAdapter mRowsAdapter;
private int eventType;
private StreamUrl mSelectedStream;
public interface PlaybackControlListener { public interface PlaybackControlListener {
void play(); void play();
@ -47,18 +56,35 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
Intent intent = getActivity() Intent intent = getActivity()
.getIntent(); .getIntent();
eventType = intent.getIntExtra(DetailsActivity.TYPE, -1);
if(eventType == DetailsActivity.TYPE_RECORDING){
mSelectedEvent = intent.getParcelableExtra(DetailsActivity.EVENT); mSelectedEvent = intent.getParcelableExtra(DetailsActivity.EVENT);
mSelectedRecording = intent.getParcelableExtra(DetailsActivity.RECORDING); mSelectedRecording = intent.getParcelableExtra(DetailsActivity.RECORDING);
mHelper = new PlaybackHelper(getActivity(),this,mSelectedEvent,mSelectedRecording);
} else if(eventType == DetailsActivity.TYPE_STREAM){
mSelectedRoom = intent.getParcelableExtra(DetailsActivity.ROOM);
mSelectedStream = intent.getParcelableExtra(DetailsActivity.STREAM_URL);
mHelper = new PlaybackHelper(getActivity(),this,mSelectedRoom,mSelectedStream);
} else {
getActivity().finish();
}
mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
setBackgroundType(PlaybackFragment.BG_LIGHT); setBackgroundType(PlaybackFragment.BG_LIGHT);
setFadingEnabled(false); setFadingEnabled(false);
mHelper = new PlaybackHelper(getActivity(),this,mSelectedEvent,mSelectedRecording);
PlaybackControlsRowPresenter playbackControlsRowPresenter PlaybackControlsRowPresenter playbackControlsRowPresenter = mHelper.getControlsRowPresenter();
= mHelper.createControlsRowAndPresenter(); // playbackControlsRowPresenter.setOnActionClickedListener(mHelper.getOnActionClickedListener());
PlaybackControlsRow controlsRow = mHelper.getControlsRow(); PlaybackControlsRow controlsRow = mHelper.getControlsRow();
mMediaControler = getActivity().getMediaController();
if(mMediaControler != null){
mMediaControler.registerCallback(mHelper.createMediaControllerCallback());
}
ClassPresenterSelector ps = new ClassPresenterSelector(); ClassPresenterSelector ps = new ClassPresenterSelector();
ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter); ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
ps.addClassPresenter(ListRow.class, new ListRowPresenter()); ps.addClassPresenter(ListRow.class, new ListRowPresenter());
@ -66,14 +92,14 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
mRowsAdapter.add(controlsRow); mRowsAdapter.add(controlsRow);
// mRowsAdapter.add(getRelatedItems()); // mRowsAdapter.add(getRelatedItems());
setAdapter(mRowsAdapter); setAdapter(mRowsAdapter);
} }
private Row getRelatedItems() { private Row getRelatedItems() {
// ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter()); ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
// TODO Add related items // TODO Add related items
// HeaderItem header = new HeaderItem(0, getString(R.string.related_movies)); HeaderItem header = new HeaderItem(0, getString(R.string.related_talks));
// return new ListRow(header, listRowAdapter); return new ListRow(header, listRowAdapter);
return null;
} }
public boolean isMediaPlaying() { public boolean isMediaPlaying() {
@ -93,8 +119,12 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
if(eventType == DetailsActivity.TYPE_STREAM){
mCallback.setVideoSource(mSelectedStream.getUrl());
} else if(eventType == DetailsActivity.TYPE_RECORDING){
mCallback.setVideoSource(mSelectedRecording.getRecordingUrl()); mCallback.setVideoSource(mSelectedRecording.getRecordingUrl());
} }
}
@Override @Override
public void onAttach(Activity context) { public void onAttach(Activity context) {