android.widget.MediaController类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中android.widget.MediaController类的一些代码示例,展示了MediaController类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaController类的具体详情如下:
包路径:android.widget.MediaController
类名称:MediaController

MediaController介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

mcontroller.show();
return false;
        Toast.LENGTH_LONG).show();
  mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setDataSource(path);
  mMediaPlayer.setDisplay(holder);
  mMediaPlayer.prepare();
  mMediaPlayer.setOnBufferingUpdateListener(this);
  mMediaPlayer.setOnVideoSizeChangedListener(this);
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mcontroller = new MediaController(this);
} catch (Exception e) {
  e.printStackTrace();
  startVideoPlayback();
mcontroller.setMediaPlayer(this);
mcontroller.setAnchorView(findViewById(R.id.mediaplayer_surfaceview_container));
handler.post(new Runnable() {
    mcontroller.setEnabled(true);
    mcontroller.show();

代码示例来源:origin: stackoverflow.com

((TextView)findViewById(R.id.now_playing_text)).setText(audioFile);
 mediaPlayer = new MediaPlayer();
 mediaPlayer.setOnPreparedListener(this);
 mediaController = new MediaController(this);
protected void onStop() {
 super.onStop();
 mediaController.hide();
 mediaPlayer.stop();
 mediaPlayer.release();
public boolean onTouchEvent(MotionEvent event) {
 mediaController.show();
 return false;
 mediaController.setMediaPlayer(this);
 mediaController.setAnchorView(findViewById(R.id.main_audio_view));
   mediaController.setEnabled(true);
   mediaController.show();

代码示例来源:origin: florent37/CameraFragment

@Override
  public boolean onTouch(View v, MotionEvent event) {
    if (mediaController == null) return false;
    if (mediaController.isShowing()) {
      mediaController.hide();
      showButtonPanel(true);
    } else {
      showButtonPanel(false);
      mediaController.show();
    }
    return false;
  }
});

代码示例来源:origin: stackoverflow.com

final VideoView video = (VideoView) findViewById(R.id.videoplayer);
     final MediaController controller = new MediaController(this);
     video.setVideoURI(Uri.parse(getIntent().getStringExtra("url")));
     video.setMediaController(controller);
     controller.setMediaPlayer(video);
     video.setOnPreparedListener(new OnPreparedListener() {
         public void onPrepared(MediaPlayer mp) {
           int duration = video.getDuration();
           video.requestFocus();
           video.start();
           controller.show();
         }
       });

代码示例来源:origin: stackoverflow.com

public class MusicPlayerActivity extends Activity implements MediaController.MediaPlayerControl{
//Do all the stuff
void initMusic(){
  mMediaController = new MediaController(this,false);
  //Note do not create any variable of mediaplayer
  mMediaController.setMediaPlayer(this);       
  mMediaController.setAnchorView(findViewById(R.id.anchorText));

  new Thread(new Runnable() {

    @Override
    public void run() {
    startService(new Intent("PLAY_MUSIC"));
    }
  }).start();
    MusicService.setPathOfSong("Provide the path");

}
}

代码示例来源:origin: daniulive/SmarterStreaming

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recorder_playback);

    Intent intent = getIntent();
    recorderFilePath = intent.getStringExtra("RecorderFilePath");

    filePathTextView = (TextView) findViewById(R.id.textViewRecoderPlaybackFilePath);
    if (recorderFilePath != null) {
      filePathTextView.setText(recorderFilePath);
    } else {
      Log.i(Tag, "recorderFilePath is null");
    }

    playVideoView = (VideoView) findViewById(R.id.VideoViewRecoderPlayback);

    if (recorderFilePath != null && !recorderFilePath.isEmpty()) {
      playVideoView.setVideoPath(recorderFilePath);
      playVideoView.setMediaController(new MediaController(this));
      playVideoView.requestFocus();
      playVideoView.start();

    }
  }
}

代码示例来源:origin: pili-engineering/PLDroidShortVideo

mProgressBarDeterminate = (ProgressBar) findViewById(R.id.progressBar);
mProgressBarDeterminate.setMax(100);
mVideoPath = getIntent().getStringExtra(MP4_PATH);
mPreviousOrientation = getIntent().getIntExtra(PREVIOUS_ORIENTATION, 1);
mMediaPlayer = new MediaPlayer();
if (mMediaPlayer != null) {
  mMediaPlayer.setOnInfoListener(mOnInfoListener);
  mMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
  mMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
  mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(this);
mMediaController.setAnchorView(mSurfaceView);

代码示例来源:origin: stackoverflow.com

MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
String _path = "/mnt/sdcard/Movies/video5.mp4";
videoView.setVideoPath(_path);
videoView.setOnPreparedListener(PreparedListener);
videoView.requestFocus();
  public void onPrepared(MediaPlayer m) {
    try {
       if (m.isPlaying()) {
         m.stop();
         m.release();
         m = new MediaPlayer();

代码示例来源:origin: stackoverflow.com

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.videoview);

  vid = (VideoView) findViewById(R.id.videoview);
  vid.setMediaController(new MediaController(this));

  Intent myIntent = getIntent();

  String uri = myIntent.getStringExtra("uri");
      Bundle b = myIntent.getExtras();

  startVideo( b.getString(uri) ); // call startVideo here

}

代码示例来源:origin: liuzho/ONE

@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_video);
    mVideoView = (VideoView) findViewById(R.id.webView);
    String url = getIntent().getStringExtra(Constant.INTENT_KEY_URL);
    mVideoView.setVideoURI(Uri.parse(url));
    mVideoView.setMediaController(new MediaController(this));
    mVideoView.start();
  }
}

代码示例来源:origin: LuckSiege/PictureSelectorLight

@Override
protected void onCreate(Bundle savedInstanceState) {
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.picture_activity_video_play);
  video_path = getIntent().getStringExtra("video_path");
  picture_left_back = (ImageView) findViewById(R.id.picture_left_back);
  mVideoView = (VideoView) findViewById(R.id.video_view);
  mVideoView.setBackgroundColor(Color.BLACK);
  iv_play = (ImageView) findViewById(R.id.iv_play);
  mMediaController = new MediaController(this);
  mVideoView.setOnCompletionListener(this);
  mVideoView.setOnPreparedListener(this);
  mVideoView.setMediaController(mMediaController);
  picture_left_back.setOnClickListener(this);
  iv_play.setOnClickListener(this);
}

代码示例来源:origin: stackoverflow.com

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview_main);
Intent n = getIntent();
String myurl = n.getStringExtra("url");
videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
Uri video = Uri.parse(myurl);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.start();
}

代码示例来源:origin: stackoverflow.com

VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
 MediaController mc = new MediaController(this);
 videoView.setMediaController(mc);
 String str = "the url to your video";
 Uri uri = Uri.parse(str);
 videoView.setVideoURI(uri);
 videoView.requestFocus();
 videoView.start();

代码示例来源:origin: florent37/CameraFragment

@Override
public void onPrepared(MediaPlayer mp) {
  mediaController = new MediaController(PreviewActivity.this);
  mediaController.setAnchorView(surfaceView);
  mediaController.setMediaPlayer(new MediaController.MediaPlayerControl() {
    @Override
    public void start() {
  int videoWidth = mp.getVideoWidth();
  int videoHeight = mp.getVideoHeight();
  mediaPlayer.start();
  mediaPlayer.seekTo(currentPlaybackPosition);

代码示例来源:origin: konradrenner/kolabnotes-android

void displayAudio(ActiveAccount account, String noteUID,Attachment attachment){
  musicView.setVisibility(View.VISIBLE);
  try {
    nowPlayingView.setText(attachment.getFileName());
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnPreparedListener(this);
    mediaController = new MediaController(getActivity());
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(getActivity(), attachmentRepository.getUriFromAttachment(account.getAccount(), account.getRootFolder(), noteUID, attachment));
    mediaPlayer.prepare();
    mediaController.show(0);
  }catch (IOException e){
    Toast.makeText(getActivity(), R.string.attachment_not_previewable, Toast.LENGTH_LONG).show();
  }
}

代码示例来源:origin: stackoverflow.com

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.video);

  mVideoView = (VideoView) findViewById(R.id.video);
  MediaController mediaController = new MediaController(this);
  mediaController.setAnchorView(mVideoView);
  mVideoView.setMediaController(mediaController);
  mVideoView.setOnCompletionListener(this);

  Intent intent = getIntent();
  path = intent.getExtras().getString("path");

  int pos = 0;
  if (savedInstanceState != null) {
    pos = savedInstanceState.getInt("pos");
  }

  playVideoFromPos(pos);
}

代码示例来源:origin: stackoverflow.com

ctlr = new MediaController(this);
ctlr.setMediaPlayer(videoView);
videoView.setMediaController(ctlr);
videoView.requestFocus();
try {
  mPlayerPosition=videoView.getCurrentPosition();
  videoView.setVideoPath(bufferFile.getAbsolutePath());
mPlayerPosition = mp.getCurrentPosition();
try {
  mp.reset();
  videoView.setVideoPath(new File("mnt/sdcard/YoutubeBuff/"
      + mBufferFile).getAbsolutePath());
  mp.seekTo(mPlayerPosition);
  videoView.start();
} catch (IllegalArgumentException e) {

代码示例来源:origin: konradrenner/kolabnotes-android

@Override
public void onStop() {
  super.onStop();
  if(mediaController != null) {
    mediaController.hide();
  }
  if(mediaPlayer != null){
    mediaPlayer.stop();
    mediaPlayer.release();
  }
}

代码示例来源:origin: florent37/CameraFragment

@Override
protected void onDestroy() {
  super.onDestroy();
  if (mediaPlayer != null) {
    mediaPlayer.release();
    mediaPlayer = null;
  }
  if (mediaController != null) {
    mediaController.hide();
    mediaController = null;
  }
}

代码示例来源:origin: stackoverflow.com

mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(this);

mediaController = new MediaController(this);

相关文章