mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-27 06:30:29 +00:00
start mediaplayerFragment and select MediaOption
This commit is contained in:
parent
60e274b959
commit
14cfeafa22
4 changed files with 50 additions and 11 deletions
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import de.nicidienase.chaosflix.R;
|
||||
import de.nicidienase.chaosflix.common.entities.PlayableItem;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Conference;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Metadata;
|
||||
|
@ -166,6 +167,16 @@ public class BrowseActivity extends TouchBaseActivity implements
|
|||
toolbar.setTitle("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playItem(PlayableItem item) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
MediaPlayerFragment playerFragment = MediaPlayerFragment.newInstance(item, -1);
|
||||
ft.replace(R.id.fragment_container,playerFragment,TAG_RETAINED_FRAGMENT);
|
||||
ft.addToBackStack(null);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
// public List<Event> getRelatedEvents(Event event, MediaApiService service){
|
||||
// List<Event> results = new ArrayList<>();
|
||||
// Metadata metadata = event.getMetadata();
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.squareup.picasso.Picasso;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import de.nicidienase.chaosflix.R;
|
||||
import de.nicidienase.chaosflix.common.entities.PlayableItem;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event;
|
||||
|
||||
public class EventDetailsFragment extends Fragment {
|
||||
|
@ -152,7 +153,9 @@ public class EventDetailsFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void play() {
|
||||
Toast.makeText(getContext(),"Play the video",Toast.LENGTH_SHORT).show();
|
||||
if(mListener != null){
|
||||
mListener.playItem(mEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -198,5 +201,6 @@ public class EventDetailsFragment extends Fragment {
|
|||
public interface OnEventDetailsFragmentInteractionListener {
|
||||
void onToolbarStateChange();
|
||||
void setActionbar(Toolbar toolbar);
|
||||
void playItem(PlayableItem item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +1,47 @@
|
|||
package de.nicidienase.chaosflix.touch.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.devbrackets.android.exomedia.ui.widget.VideoView;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Optional;
|
||||
import de.nicidienase.chaosflix.R;
|
||||
import de.nicidienase.chaosflix.common.entities.PlayableItem;
|
||||
|
||||
public class MediaPlayerFragment extends Fragment {
|
||||
private static final String ARG_TITLE = "title";
|
||||
private static final String ARG_URL = "url";
|
||||
private static final String ARG_ITEM = "title";
|
||||
private static final String ARG_INDEX = "index";
|
||||
|
||||
private String mTitle;
|
||||
private String mVideoURL;
|
||||
private OnMediaPlayerInteractionListener mListener;
|
||||
|
||||
@BindView(R.id.video_view)
|
||||
VideoView videoView;
|
||||
private PlayableItem mItem;
|
||||
private int mIndex = -1;
|
||||
|
||||
public MediaPlayerFragment() {
|
||||
}
|
||||
|
||||
public static MediaPlayerFragment newInstance(String title, String videoURL) {
|
||||
public static MediaPlayerFragment newInstance(PlayableItem item, int index) {
|
||||
MediaPlayerFragment fragment = new MediaPlayerFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_TITLE, title);
|
||||
args.putString(ARG_URL,videoURL);
|
||||
args.putParcelable(ARG_ITEM, item);
|
||||
args.putInt(ARG_INDEX,index);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
@ -41,9 +49,10 @@ public class MediaPlayerFragment extends Fragment {
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
if (getArguments() != null) {
|
||||
mTitle = getArguments().getString(ARG_TITLE);
|
||||
mVideoURL = getArguments().getString(ARG_URL);
|
||||
mItem = getArguments().getParcelable(ARG_ITEM);
|
||||
mIndex = getArguments().getInt(ARG_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,9 +69,23 @@ public class MediaPlayerFragment extends Fragment {
|
|||
ButterKnife.bind(this,view);
|
||||
|
||||
videoView.setOnPreparedListener(() -> videoView.start());
|
||||
videoView.setVideoURI(Uri.parse(mVideoURL));
|
||||
if(mIndex >= 0){
|
||||
setVideoByIndex(mIndex);
|
||||
} else {
|
||||
List<String> strings = mItem.getPlaybackOptions();
|
||||
CharSequence[] options = strings.toArray(new CharSequence[strings.size()]);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.select_option)
|
||||
.setItems(options,(dialog, which) -> setVideoByIndex(which))
|
||||
.create().show();
|
||||
}
|
||||
}
|
||||
|
||||
private void setVideoByIndex(int index) {
|
||||
videoView.setVideoURI(Uri.parse(mItem.getUrlForOption(index)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
<string name="subtitle">subtitle</string>
|
||||
<string name="thumbnail">thumbnail</string>
|
||||
<string name="card">card</string>
|
||||
<string name="select_option">Select Media Option</string>
|
||||
</resources>
|
Loading…
Reference in a new issue