本文整理汇总了Java中android.widget.MediaController类的典型用法代码示例。如果您正苦于以下问题:Java MediaController类的具体用法?Java MediaController怎么用?Java MediaController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaController类属于android.widget包,在下文中一共展示了MediaController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the video view by id so we can use it.
VideoView myVideo = (VideoView) findViewById(R.id.videoView);
// To set the path to the video. Sample.mp4 is in the "raw" folder.
// You can use http://online.path.to.your.video also.
myVideo.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.sample);
// To create the media controller (play, pause, etc.)
MediaController myController = new MediaController(this);
// To link the media controller to the video view.
myController.setAnchorView(myVideo);
// To link the video view to the media controller.
myVideo.setMediaController(myController);
// To autoplay on opening.
myVideo.start();
}
示例2: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
VideoView videoView = new VideoView(this);
setContentView(videoView);
videoView.setMediaController(new MediaController(this));
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Toast.makeText( VideoPlayerActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();
}
});
String videoPath = getIntent().getStringExtra("videoPath");
try {
videoView.setVideoPath(videoPath);
videoView.start();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(VideoPlayerActivity.this, "视频不存在", Toast.LENGTH_SHORT).show();
}
}
示例3: init
import android.widget.MediaController; //导入依赖的package包/类
private void init() {
BaseConfig.sPositionWhenPaused = -1;
// Create media controller
MediaController mediaController = new MediaController(this);
// 设置MediaController
mVideoView.setMediaController(mediaController);
mVideoView.setOnCompletionListener(this);
mVideoView.setOnErrorListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mVideoView.setOnInfoListener(this);
} else {
mLoadingView.setVisibility(View.GONE);
}
mVideoView.setOnPreparedListener(this);
mGestureDetector = new GestureDetector(this, new MyGestureListener());
Uri uri = Uri.parse(mVideoUrl);
mVideoView.setVideoURI(uri);
}
示例4: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = getIntent().getExtras().getString(Constants.URL);
setContentView(R.layout.fragment_video_gallery);
final VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
View progress = findViewById(R.id.videoProgress);
progress.setVisibility(View.GONE);
videoView.requestFocus();
MediaController vidControl = new MediaController(VideoPlayerActivity.this);
vidControl.setAnchorView(videoView);
videoView.setMediaController(vidControl);
videoView.start();
}
});
videoView.setVideoURI(Uri.parse(url));
}
示例5: VideoPlayer
import android.widget.MediaController; //导入依赖的package包/类
/**
* Creates a new VideoPlayer component.
*
* @param container
*/
public VideoPlayer(ComponentContainer container) {
super(container);
container.$form().registerForOnDestroy(this);
videoView = new ResizableVideoView(container.$context());
videoView.setMediaController(new MediaController(container.$context()));
videoView.setOnCompletionListener(this);
videoView.setOnErrorListener(this);
videoView.setOnPreparedListener(this);
// add the component to the designated container
container.$add(this);
// set a default size
container.setChildWidth(this,
ComponentConstants.VIDEOPLAYER_PREFERRED_WIDTH);
container.setChildHeight(this,
ComponentConstants.VIDEOPLAYER_PREFERRED_HEIGHT);
// Make volume buttons control media, not ringer.
container.$form().setVolumeControlStream(AudioManager.STREAM_MUSIC);
sourcePath = "";
}
示例6: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media_details);
ButterKnife.bind(this);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
storageRef = FirebaseStorage.getInstance().getReference().child
(uid);
Intent incoming = getIntent();
if (incoming.hasExtra("FIREBASE_REF")) {
String fbUrl = incoming.getStringExtra("FIREBASE_REF");
FirebaseDatabase db = FirebaseDatabase.getInstance();
entriesRef = db.getReferenceFromUrl(fbUrl);
}
if (incoming.hasExtra("PHOTO_URI")) {
mediaType = 2;
try {
dataUri = incoming.getParcelableExtra("PHOTO_URI");
InputStream istr = getContentResolver().openInputStream
(dataUri);
Bitmap bmp = BitmapFactory.decodeStream(istr);
photoView.setImageBitmap(bmp);
istr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (incoming.hasExtra("VIDEO_URI")) {
mediaType = 4;
dataUri = incoming.getParcelableExtra("VIDEO_URI");
videoView.setVideoURI(dataUri);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
photoView.setVisibility(View.INVISIBLE);
videoView.setVisibility(View.VISIBLE);
}
}
示例7: onPrepared
import android.widget.MediaController; //导入依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
if(mHasVideo) {
mediaPlayer.start();
mediaPlayer.setVolume(0,0);
setVideoSize();
vidSurface.bringToFront();
vidSurface.requestFocus();
MediaController mController = new MediaController(context);
mController.setMediaPlayer(this);
mController.setAnchorView(vidSurface);
// mController.show(0);
vidSurface.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
}
}
示例8: setMediaController
import android.widget.MediaController; //导入依赖的package包/类
public void setMediaController(Context context, View view)
{
if (view instanceof MediaController) {
MediaController v = (MediaController) view;
for (int i = 0; i < v.getChildCount(); i++)
{
this.setMediaController(context, v.getChildAt(i));
}
}
else if (view instanceof LinearLayout)
{
LinearLayout ll = (LinearLayout) view;
for (int i = 0; i < ll.getChildCount(); i++)
{
this.setMediaController(context, ll.getChildAt(i));
}
}
else if (view instanceof SeekBar)
{
((SeekBar) view).getProgressDrawable().mutate().setColorFilter(context.getResources().getColor(getColorTheme(context)),PorterDuff.Mode.SRC_IN);
}
}
示例9: onVideoReady
import android.widget.MediaController; //导入依赖的package包/类
private void onVideoReady() {
MediaController mediaController = new MediaController(this);
videoViewPreview.setVisibility(View.VISIBLE);
videoViewPreview.setVideoPath(videoFileName);
videoViewPreview.setMediaController(mediaController);
videoViewPreview.requestFocus();
videoViewPreview.start();
videoViewPreview.pause();
textViewFilePath.setText(videoFileName);
editTextVideoTitle.setText("");
editTextVideoDescription.setText("");
textViewVideoUrl.setText(getString(R.string.noUrlYet));
Toast.makeText(this, R.string.pressVideoToPreview, Toast.LENGTH_LONG).show();
}
示例10: onVideoReady
import android.widget.MediaController; //导入依赖的package包/类
private void onVideoReady() {
MediaController mediaController = new MediaController(this);
videoViewPreview.setVisibility(View.VISIBLE);
videoViewPreview.setVideoPath(videoFileName);
videoViewPreview.setMediaController(mediaController);
videoViewPreview.requestFocus();
videoViewPreview.start();
videoViewPreview.pause();
imageButtonUploadVideo.setEnabled(true);
imageButtonUploadVideo.setImageResource(R.drawable.upload);
textViewFilePath.setText(videoFileName);
editTextVideoTitle.setText("");
editTextVideoDescription.setText("");
textViewVideoUrl.setText(getString(R.string.noUrlYet));
Toast.makeText(this, R.string.pressVideoToPreview, Toast.LENGTH_LONG).show();
}
示例11: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
// Load the appropriate URL in the VideoView.
final String youtubeId = getIntent().getStringExtra(Keys.YOUTUBE_ID);
final String videoUrl = UrlBuilder.forYoutubeId(youtubeId);
final VideoView videoView = (VideoView) findViewById(R.id.video_view);
videoView.setVideoPath(videoUrl);
videoView.start();
// Add a MediaController, which gives us play/pause, etc.
final MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
}
示例12: ponInfoLibro
import android.widget.MediaController; //导入依赖的package包/类
private void ponInfoLibro(int id, View vista) {
/*Libro*/ libro = ((Aplicacion) getActivity().getApplication())
.getVectorLibros().elementAt(id);
((TextView) vista.findViewById(R.id.titulo)).setText(libro.titulo);
((TextView) vista.findViewById(R.id.autor)).setText(libro.autor);
((ImageView) vista.findViewById(R.id.portada))
.setImageResource(libro.recursoImagen);
vista.setOnTouchListener(this);
if (mediaPlayer != null){
mediaPlayer.release();
}
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(this);
mediaController = new MediaController(getActivity());
Uri audio = Uri.parse(libro.urlAudio);
try {
mediaPlayer.setDataSource(getActivity(), audio);
mediaPlayer.prepareAsync();
} catch (IOException e) {
Log.e("Audiolibros", "ERROR: No se puede reproducir "+audio,e);
}
}
示例13: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
public void onCreate(final @Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_player_layout);
ButterKnife.bind(this);
this.viewModel.outputs.preparePlayerWithUrl()
.compose(Transformers.takeWhen(lifecycle().filter(ActivityEvent.RESUME::equals)))
.compose(bindToLifecycle())
.subscribe(this::preparePlayer);
this.mediaController = new MediaController(this);
this.mediaController.setAnchorView(this.rootView);
RxView.clicks(this.rootView)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(__ -> toggleControlsVisibility());
}
示例14: onCreate
import android.widget.MediaController; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_full);
videofull=(VideoView)findViewById(R.id.videofull);
videofull.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video));
videofull.setMediaController(new MediaController(VideoFull.this));
videofull.start();
videofull.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
videofull.requestFocus();
}
示例15: PlayerControl
import android.widget.MediaController; //导入依赖的package包/类
public PlayerControl(@NonNull MediaControllerCompat mediaControllerCompat, final MediaController mediaController) {
mMediaControllerCompat = mediaControllerCompat;
mCallback = new MediaControllerCompat.Callback() {
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
processPlaybackState(state, mediaController);
}
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
mLastMediaMetadataCompat = metadata;
}
};
mMediaControllerCompat.registerCallback(mCallback);
mLastMediaMetadataCompat = mMediaControllerCompat.getMetadata();
processPlaybackState(mMediaControllerCompat.getPlaybackState(), mediaController);
}