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){
Event event = (Event) item;
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
i.putExtra(DetailsActivity.TYPE,DetailsActivity.TYPE_RECORDING);
i.putExtra(DetailsActivity.EVENT,event);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
fragment.getActivity(),
@ -55,6 +56,7 @@ public class ItemViewClickedListener implements OnItemViewClickedListener {
if(item instanceof Room){
Room room = (Room) item;
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
i.putExtra(DetailsActivity.TYPE,DetailsActivity.TYPE_STREAM);
i.putExtra(DetailsActivity.ROOM,room);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
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.streaming.Room;
import de.nicidienase.chaosflix.entities.streaming.Stream;
import de.nicidienase.chaosflix.entities.streaming.StreamUrl;
import de.nicidienase.chaosflix.fragments.ExoOverlayFragment;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -34,7 +35,7 @@ public class PlaybackHelper extends PlaybackControlGlue {
private final ExoOverlayFragment mFragment;
private BitmapDrawable mDrawable = null;
private Room room;
private Stream stream;
private StreamUrl stream;
private Event event;
private Recording recording;
private Runnable mUpdateProgressRunnable;
@ -47,6 +48,9 @@ public class PlaybackHelper extends PlaybackControlGlue {
this.event = event;
this.recording = recording;
controlListener = (ExoOverlayFragment.PlaybackControlListener) context;
if(event != null){
Observable.fromCallable(() ->
new BitmapDrawable(
mContext.getResources(),
@ -60,9 +64,10 @@ public class PlaybackHelper extends PlaybackControlGlue {
.doOnError(Throwable::printStackTrace)
.subscribe(bitmapDrawable -> mDrawable = bitmapDrawable);
}
}
public PlaybackHelper(Context context, ExoOverlayFragment fragment, Room room, Stream stream ){
super(context, fragment,SEEK_SPEEDS);
public PlaybackHelper(Context context, ExoOverlayFragment fragment, Room room, StreamUrl stream ){
super(context, SEEK_SPEEDS);
this.mContext = context;
this.mFragment = fragment;
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 EVENT = "event";
public static final String ROOM = "room";
public static final String STREAM_URL = "stream_url";
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.

View file

@ -14,7 +14,8 @@ import java.util.List;
public class Event extends SugarRecord implements Parcelable, Comparable<Event> {
int parentConferenceID;
@SerializedName("conference_id")
int conferenceId;
String guid;
String title;
String subtitle;
@ -42,6 +43,7 @@ public class Event extends SugarRecord implements Parcelable, Comparable<Event>
String conferenceUrl;
List<Recording> recordings;
protected Event(Parcel in) {
guid = 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]);
}
public long getParentConferenceID() {
if(parentConferenceID == 0){
public long getConferenceId() {
if(conferenceId == 0){
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) {
this.parentConferenceID = parentConferenceID;
public void setConferenceId(int conferenceId) {
this.conferenceId = conferenceId;
}
public String getGuid() {

View file

@ -4,7 +4,6 @@ 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;
@ -17,7 +16,6 @@ import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElement
import android.support.v17.leanback.widget.HeaderItem;
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.Presenter;
import android.util.Log;
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.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;
import de.nicidienase.chaosflix.entities.recording.Recording;
@ -68,6 +65,8 @@ public class EventsDetailsFragment extends DetailsFragment {
private Event mSelectedEvent;
private MediaApiService mMediaApiService;
private Room mRoom;
private int eventType;
private ArrayList<StreamUrl> streamUrlList;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -76,10 +75,15 @@ public class EventsDetailsFragment extends DetailsFragment {
final BrowseErrorFragment browseErrorFragment =
BrowseErrorFragment.showErrorFragment(getFragmentManager(),FRAGMENT);
eventType = getActivity().getIntent().getIntExtra(DetailsActivity.TYPE, -1);
if(eventType == DetailsActivity.TYPE_RECORDING){
mSelectedEvent = getActivity().getIntent()
.getParcelableExtra(DetailsActivity.EVENT);
} else if(eventType == DetailsActivity.TYPE_STREAM){
mRoom = getActivity().getIntent()
.getParcelableExtra(DetailsActivity.ROOM);
}
final ArrayObjectAdapter adapter = setupDetailsOverviewRowPresenter();
@ -87,7 +91,7 @@ public class EventsDetailsFragment extends DetailsFragment {
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
.subscribe(mediaApiService -> {
mMediaApiService = mediaApiService;
if(mSelectedEvent != null){
if(eventType == DetailsActivity.TYPE_RECORDING){
final DetailsOverviewRow detailsOverviewRow = setupDetailsOverviewRow(mSelectedEvent);
mediaApiService.getEvent(mSelectedEvent.getApiID())
.doOnError(t -> browseErrorFragment.setErrorContent(t.getMessage()))
@ -98,7 +102,7 @@ public class EventsDetailsFragment extends DetailsFragment {
detailsOverviewRow.setActionsAdapter(recordingActionsAdapter);
adapter.add(detailsOverviewRow);
mediaApiService.getConference(
mSelectedEvent.getParentConferenceID())
mSelectedEvent.getConferenceId())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(conference -> {
String tag = null;
@ -132,7 +136,7 @@ public class EventsDetailsFragment extends DetailsFragment {
browseErrorFragment.dismiss();
});
});
} else if(mRoom != null){
} else if(eventType == DetailsActivity.TYPE_STREAM){
mediaApiService.getStreamingConferences()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(liveConferences -> {
@ -201,21 +205,27 @@ public class EventsDetailsFragment extends DetailsFragment {
mDetailsPresenter.setListener(helper);
prepareEntranceTransition();
mDetailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@Override
public void onActionClicked(Action action) {
// Intent i = new Intent(getActivity(), PlaybackOverlayActivity.class);
mDetailsPresenter.setOnActionClickedListener(action -> {
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()){
if(r.getApiID() == action.getId()){
i.putExtra(DetailsActivity.RECORDING,r);
break;
}
}
i.putExtra(DetailsActivity.EVENT,mSelectedEvent);
getActivity().startActivity(i);
} else if(eventType == DetailsActivity.TYPE_STREAM){
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();
@ -260,6 +270,7 @@ public class EventsDetailsFragment extends DetailsFragment {
private ArrayObjectAdapter getRecordingActionsAdapter(List<Recording> recordings) {
ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter();
if(recordings != null){
for(int i = 0; i < recordings.size(); i++){
Recording recording = recordings.get(i);
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)));
}
}
}
return actionsAdapter;
}
private ArrayObjectAdapter getStreamActionsAdapter(List<Stream> streams){
ArrayObjectAdapter actionsAdapter = new ArrayObjectAdapter();
streamUrlList = new ArrayList<StreamUrl>();
for(Stream s: streams){
if(s.getType().equals("video"))
for(String key :s.getUrls().keySet()){
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;
}
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 ViewHolder extends DetailsOverviewLogoPresenter.ViewHolder {
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.widget.ArrayObjectAdapter;
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.ListRowPresenter;
import android.support.v17.leanback.widget.PlaybackControlsRow;
import android.support.v17.leanback.widget.PlaybackControlsRowPresenter;
import android.support.v17.leanback.widget.Row;
import de.nicidienase.chaosflix.CardPresenter;
import de.nicidienase.chaosflix.PlaybackHelper;
import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.activities.DetailsActivity;
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.StreamUrl;
/**
* 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 Event mSelectedEvent;
private Room mSelectedRoom;
private PlaybackHelper mHelper;
private PlaybackControlListener mCallback;
private ArrayObjectAdapter mRowsAdapter;
private int eventType;
private StreamUrl mSelectedStream;
public interface PlaybackControlListener {
void play();
@ -47,18 +56,35 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
Intent intent = getActivity()
.getIntent();
eventType = intent.getIntExtra(DetailsActivity.TYPE, -1);
if(eventType == DetailsActivity.TYPE_RECORDING){
mSelectedEvent = intent.getParcelableExtra(DetailsActivity.EVENT);
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);
setFadingEnabled(false);
mHelper = new PlaybackHelper(getActivity(),this,mSelectedEvent,mSelectedRecording);
PlaybackControlsRowPresenter playbackControlsRowPresenter
= mHelper.createControlsRowAndPresenter();
PlaybackControlsRowPresenter playbackControlsRowPresenter = mHelper.getControlsRowPresenter();
// playbackControlsRowPresenter.setOnActionClickedListener(mHelper.getOnActionClickedListener());
PlaybackControlsRow controlsRow = mHelper.getControlsRow();
mMediaControler = getActivity().getMediaController();
if(mMediaControler != null){
mMediaControler.registerCallback(mHelper.createMediaControllerCallback());
}
ClassPresenterSelector ps = new ClassPresenterSelector();
ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
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(getRelatedItems());
setAdapter(mRowsAdapter);
}
private Row getRelatedItems() {
// ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
// TODO Add related items
// HeaderItem header = new HeaderItem(0, getString(R.string.related_movies));
// return new ListRow(header, listRowAdapter);
return null;
HeaderItem header = new HeaderItem(0, getString(R.string.related_talks));
return new ListRow(header, listRowAdapter);
}
public boolean isMediaPlaying() {
@ -93,8 +119,12 @@ public class ExoOverlayFragment extends android.support.v17.leanback.app.Playbac
@Override
public void onStart() {
super.onStart();
if(eventType == DetailsActivity.TYPE_STREAM){
mCallback.setVideoSource(mSelectedStream.getUrl());
} else if(eventType == DetailsActivity.TYPE_RECORDING){
mCallback.setVideoSource(mSelectedRecording.getRecordingUrl());
}
}
@Override
public void onAttach(Activity context) {