pass Event and Recording to ExoPlayerFragment

This commit is contained in:
Felix 2017-09-24 22:10:36 +02:00
parent fb72d101cb
commit b149205937
3 changed files with 20 additions and 20 deletions

View file

@ -16,6 +16,7 @@ import android.view.View;
import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.common.entities.recording.Conference;
import de.nicidienase.chaosflix.common.entities.recording.Event;
import de.nicidienase.chaosflix.common.entities.recording.Recording;
import de.nicidienase.chaosflix.touch.fragments.ConferencesTabBrowseFragment;
import de.nicidienase.chaosflix.touch.fragments.EventDetailsFragment;
import de.nicidienase.chaosflix.touch.fragments.EventsFragment;
@ -158,10 +159,10 @@ public class BrowseActivity extends TouchBaseActivity implements
}
@Override
public void playItem(String title, String subtitle, String url) {
public void playItem(Event event, Recording recording) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment playerFragment = ExoPlayerFragment.newInstance(title,subtitle,url);
Fragment playerFragment = ExoPlayerFragment.newInstance(event,recording);
ft.replace(R.id.fragment_container,playerFragment,TAG_RETAINED_FRAGMENT);
ft.addToBackStack(null);
ft.commit();

View file

@ -20,6 +20,7 @@ import com.squareup.picasso.Picasso;
import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.common.entities.recording.Event;
import de.nicidienase.chaosflix.common.entities.recording.Recording;
import de.nicidienase.chaosflix.databinding.FragmentEventDetailsNewBinding;
public class EventDetailsFragment extends Fragment {
@ -107,7 +108,7 @@ public class EventDetailsFragment extends Fragment {
private void play() {
if(mListener != null){
mListener.playItem(mEvent.getTitle(),mEvent.getSubtitle(),mEvent.getOptimalStream());
mListener.playItem(mEvent,mEvent.getOptimalStream());
}
}
@ -154,6 +155,6 @@ public class EventDetailsFragment extends Fragment {
public interface OnEventDetailsFragmentInteractionListener {
void onToolbarStateChange();
void setActionbar(Toolbar toolbar);
void playItem(String title, String subtitle, String url);
void playItem(Event event, Recording recording);
}
}

View file

@ -48,13 +48,14 @@ import com.google.android.exoplayer2.util.Util;
import butterknife.BindView;
import butterknife.ButterKnife;
import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.common.entities.recording.Event;
import de.nicidienase.chaosflix.common.entities.recording.Recording;
public class ExoPlayerFragment extends Fragment {
private static final String ARG_TITEL = "title";
private static final String ARG_SUBTITLE = "subtitle";
private static final String ARG_URL = "url";
private static final String TAG = ExoPlayerFragment.class.getSimpleName();
public static final String PLAYBACK_STATE = "playback_state";
private static final String ARG_EVENT = "event";
private static final String ARG_RECORDING = "recording";
private OnMediaPlayerInteractionListener mListener;
private final DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
@ -71,23 +72,21 @@ public class ExoPlayerFragment extends Fragment {
@BindView(R.id.subtitle_text)
TextView subtitleText;
private String mTitle;
private String mSubtitle;
private String mUrl;
private SimpleExoPlayer mPlayer;
private String mUserAgent;
private Handler mainHandler = new Handler();
private boolean mPlaybackState = true;
private Event mEvent;
private Recording mRecording;
public ExoPlayerFragment() {
}
public static ExoPlayerFragment newInstance(String title, String subtitle, String url) {
public static ExoPlayerFragment newInstance(Event event, Recording recording) {
ExoPlayerFragment fragment = new ExoPlayerFragment();
Bundle args = new Bundle();
args.putString(ARG_TITEL, title);
args.putString(ARG_SUBTITLE, subtitle);
args.putString(ARG_URL, url);
args.putParcelable(ARG_EVENT,event);
args.putParcelable(ARG_RECORDING,recording);
fragment.setArguments(args);
return fragment;
}
@ -97,9 +96,8 @@ public class ExoPlayerFragment extends Fragment {
super.onCreate(savedInstanceState);
setRetainInstance(true);
if (getArguments() != null) {
mTitle = getArguments().getString(ARG_TITEL);
mSubtitle = getArguments().getString(ARG_SUBTITLE);
mUrl = getArguments().getString(ARG_URL);
mEvent = getArguments().getParcelable(ARG_EVENT);
mRecording = getArguments().getParcelable(ARG_RECORDING);
}
if(savedInstanceState != null){
mPlaybackState = savedInstanceState.getBoolean(PLAYBACK_STATE,true);
@ -117,9 +115,9 @@ public class ExoPlayerFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this,view);
if(titleText != null)
titleText.setText(mTitle);
titleText.setText(mEvent.getTitle());
if(subtitleText != null)
subtitleText.setText(mSubtitle);
subtitleText.setText(mEvent.getSubtitle());
if(mPlayer == null){
setupPlayer();
@ -176,7 +174,7 @@ public class ExoPlayerFragment extends Fragment {
mVideoView.setPlayer(mPlayer);
mPlayer.setPlayWhenReady(mPlaybackState);
mPlayer.prepare(buildMediaSource(Uri.parse(mUrl),""));
mPlayer.prepare(buildMediaSource(Uri.parse(mRecording.getRecordingUrl()),""));
}
@Override