Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class DetailFragment extends Fragment {
// public List<Step> step;
public ArrayList < Step > stepList;
public Step currentStep;
public ExoPlayer mExoPlayer;
public SimpleExoPlayerView mPlayerView;
public int position;
public String videoURL;
public Uri videoUri;
public TextView textView;
public String thumbnailURL;
public String description;
public Button nextButton;
public DetailFragment() {
// Required empty public constructor
}
public void showCurrentStep(Step currentStep) {
videoURL = currentStep.getVideoURL();
videoUri = Uri.parse(videoURL);
initializePlayer(videoUri);
Log.i("videoUrl", currentStep.getVideoURL());
thumbnailURL = currentStep.getThumbnailURL();
description = currentStep.getDescription();
}
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
mPlayerView = (SimpleExoPlayerView) rootView.findViewById(R.id.video);
nextButton = (Button) rootView.findViewById(R.id.next);
textView = (TextView) rootView.findViewById(R.id.steps);
textView.setText(description);
// Inflate the layout for this fragment
// Step steps = getArguments().getParcelable("Step");
stepList = getArguments().getParcelableArrayList("Steps");
position = getArguments().getInt("position");
currentStep = stepList.get(position);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
position++;
currentStep = stepList.get(position);
if (position >= stepList.size()) {
nextButton.setEnabled(true);
showCurrentStep(currentStep);
initializePlayer(videoUri);
}
}
});
return rootView;
}
public void initializePlayer(Uri videoURL) {
if (mExoPlayer == null) {
TrackSelector trackSelector = new DefaultTrackSelector();
LoadControl loadControl = new DefaultLoadControl();
mExoPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector, loadControl);
mPlayerView.setPlayer((SimpleExoPlayer) mExoPlayer);
String userAgent = Util.getUserAgent(getContext(), "Baking App");
MediaSource mediaSource = new ExtractorMediaSource(videoURL,
new DefaultDataSourceFactory(getContext(), userAgent),
new DefaultExtractorsFactory(), null, null);
mExoPlayer.prepare(mediaSource);
mExoPlayer.setPlayWhenReady(true);
}
}
private void releasePlayer() {
mExoPlayer.stop();
mExoPlayer.release();
mExoPlayer = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.