The is an fragment that display the video.
This fragment can either
1) open a new activity on click button
2) replace with another fragment by calling
fragmentManager.beginTransaction().replace(R.id.container, f).addToBackStack(tag).commit();
for the 1) case , I would like to call player.stopPlayBack()
to stop the video playing at backing
And for the 2) case , I would like to call player.stopPlayBack()
and player.release()
to terminate the player
The problem is , what event I should call for the case 1) and 2)? I try using onPause or onStop but both of them seems has not fired.
How to fix it?
Thanks a lot for helping.
Updated:
Video fragment code
public class Video extends Fragment implements MediaPlayer.OnPreparedListener {
@Bind(R.id.player) EMVideoView player;
@Bind(R.id.full_screen) ImageView full_screen;
Context ctx;
MyApp app;
String video_url;
int intent_code = 5545;
int pos;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.video, container, false);
ButterKnife.bind(this, view);
Bundle bundle = this.getArguments();
video_url = bundle.getString("video_url");
String id = bundle.getString("id");
app = (MyApp) getActivity().getApplicationContext();
app.record_view(id);
Main m = (Main)getActivity();
m.toggle_upload_btn(false);
pos = 0;
full_screen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(), VideoFullScreen.class);
i.putExtra("video_url", video_url);
i.putExtra("time", (int) player.getCurrentPosition());
startActivityForResult(i, intent_code); //random intent number
}
});
return view;
}
@Override
public void onPrepared(MediaPlayer mp) {
player.seekTo(pos);
player.start();
}
@Override
public void onResume() {
super.onResume();
player.setOnPreparedListener(this);
player.setVideoURI(Uri.parse(video_url));
}
@Override
public void onStop() {
super.onStop();
player.stopPlayback();
//player.release();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == intent_code) {
if(resultCode == Activity.RESULT_OK){
pos = data.getIntExtra("time", 0);
}
}
}