Skip to content

Instantly share code, notes, and snippets.

@mklimek
Last active April 23, 2019 15:48
Show Gist options
  • Save mklimek/1a7e5497292b9d945ef1e143d152e312 to your computer and use it in GitHub Desktop.
Save mklimek/1a7e5497292b9d945ef1e143d152e312 to your computer and use it in GitHub Desktop.
frame-viedo-view simple usage with possibility to manipulate MediaPlayer basic actions
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.mklimek.framevideoview.FrameVideoView;
import com.mklimek.framevideoview.FrameVideoViewListener;
public class SimpleUsageActivity extends Activity {
private FrameVideoView videoView;
private MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple);
setupFrameVideoView();
setupOtherViews();
}
@Override
protected void onResume() {
super.onResume();
videoView.onResume();
}
@Override
protected void onPause() {
videoView.onPause();
super.onPause();
}
private void setupFrameVideoView() {
videoView = (FrameVideoView) findViewById(R.id.frame_video_view);
videoView.setup(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fb), getResources().getColor(R.color.background));
videoView.setFrameVideoViewListener(new FrameVideoViewListener() {
@Override
public void mediaPlayerPrepared(final MediaPlayer mediaPlayer) {
SimpleUsageActivity.this.mediaPlayer = mediaPlayer;
}
@Override
void mediaPlayerPrepareFailed( MediaPlayer mediaPlayer, String error ){
}
});
}
private void setupOtherViews() {
View resumeButton = findViewById(R.id.resume_button);
resumeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mediaPlayer.start();
}
});
View pauseButton = findViewById(R.id.pause_button);
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mediaPlayer.pause();
}
});
View button = findViewById(R.id.change_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SimpleUsageActivity.this, ViewPagerActivity.class));
}
});
TextView info = (TextView) findViewById(R.id.info);
info.setText(videoView.getImplType().name());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment