android.widget.MediaController源码实例Demo

类android.widget.MediaController源码实例Demo

下面列出了android.widget.MediaController 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void play() {
	mProgressBar.setVisibility(View.VISIBLE);
	Uri videoUri = Uri.parse(mVideoUrl);
	try {
		mVideoView.setOnCompletionListener(this);
		mVideoView.setOnPreparedListener(this);
		mVideoView.setOnErrorListener(this);
		mVideoView.setVideoURI(videoUri);
		mMediaController = new MediaController(this);
		mMediaController.setAnchorView(mVideoView);
		mMediaController.setMediaPlayer(mVideoView);
		if (!mControls) {
			mMediaController.setVisibility(View.GONE);
		}
		mVideoView.setMediaController(mMediaController);
	} catch (Throwable t) {
		Log.d(TAG, t.toString());
	}
}
 
源代码2 项目: 4pdaClient-plus   文件: PlayerActivity.java
private void playVideo(VideoItem parseResult, Uri pResult) {
    try {
        createActionMenu(parseResult);
        mSeekTo = mVideoView.getCurrentPosition();
        mVideoView.setVideoURI(pResult);

        mVideoView.setMediaController(new MediaController(this));

        mVideoView.setKeepScreenOn(true);

        mVideoView.requestFocus();

        mVideoView.start();
    } catch (Throwable ex) {
        AppLog.toastE(getContext(), ex);
    }
}
 
源代码3 项目: appinventor-extensions   文件: VideoPlayer.java
/**
 * 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 = "";
}
 
源代码4 项目: MediaPlayer-Extended   文件: VideoViewActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_videoview);
    Utils.setActionBarSubtitleEllipsizeMiddle(this);

    mVideoView = (VideoView) findViewById(R.id.vv);
    mProgress = (ProgressBar) findViewById(R.id.progress);

    mMediaPlayerControl = mVideoView; //new MediaPlayerDummyControl();
    mMediaController = new MediaController(this);
    mMediaController.setAnchorView(findViewById(R.id.container));
    mMediaController.setMediaPlayer(mMediaPlayerControl);
    mMediaController.setEnabled(false);

    mProgress.setVisibility(View.VISIBLE);

    // Init video playback state (will eventually be overwritten by saved instance state)
    mVideoUri = getIntent().getData();
    mVideoPosition = 0;
    mVideoPlaybackSpeed = 1;
    mVideoPlaying = false;
}
 
源代码5 项目: kolabnotes-android   文件: PreviewFragment.java
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();
    }

}
 
源代码6 项目: android-tv-leanback   文件: PlayerActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mVideo = (Video)getIntent().getSerializableExtra(Video.INTENT_EXTRA_VIDEO);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    preparePlayer();
}
 
源代码7 项目: android-tv-leanback   文件: PlayerActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mVideo = (Video) getIntent().getSerializableExtra(Video.INTENT_EXTRA_VIDEO);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    preparePlayer();
}
 
源代码8 项目: codeexamples-android   文件: VideoViewDemo.java
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.videoview);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                VideoViewDemo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

    }
}
 
源代码9 项目: ResearchStack   文件: ViewVideoActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.rsb_activity_video_viewer);

    videoView = (AssetVideoView) findViewById(R.id.videoView);

    MediaController mediaController = new MediaController(this, false);
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    try {
        String videoPath = getIntent().getStringExtra(KEY_RELATIVE_PATH);
        AssetFileDescriptor afd = getAssets().openFd(videoPath);
        videoView.setVideoDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        videoView.start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
源代码10 项目: ScrollGalleryView   文件: VideoPlayerActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String url = getIntent().getExtras().getString(Constants.URL);
    setContentView(R.layout.video_fragment);
    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));
}
 
源代码11 项目: goprohero   文件: LiveStuff.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_live_stuff);
    myVideoView = (VideoView)this.findViewById(R.id.videoView);
    MediaController mc = new MediaController(this);
    myVideoView.setMediaController(mc);
    urlStream = "http://10.5.5.9:8080/live/amba.m3u8";
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            myVideoView.setVideoURI(Uri.parse(urlStream));
            myVideoView.start();
        }

    });

}
 
源代码12 项目: fitness_Android   文件: VideoPlayer.java
private void loadVideo() {
    // String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/movie.mp4";
    String uri = "android.resource://" + getPackageName() + "/";
    switch (tag) {
        case 1:
            duration = "8";
            uri += R.raw.base;
            break;
        case 2:
            duration = "9";
            uri += R.raw.enhance;
            break;
        case 3:
            duration = "11";
            uri += R.raw.acme;
            break;
    }
    // 本地视频
    // videoView.setVideoPath(path);
    // 网络视频
    // videoView.setVideoURI(Uri.parse("http://www.runoob.com/try/demo_source/movie.mp4"));
    videoView.setVideoURI(Uri.parse(uri));
    mediaController = new MediaController(this);
    videoView.setMediaController(mediaController);
    mediaController.setMediaPlayer(videoView);
    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            videoStop = true;
            saveTrainRecord();
        }
    });
    videoView.start();
}
 
源代码13 项目: fitness_Android   文件: VideoPlayer.java
@Override
protected void initView() {
    // String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/movie.mp4";
    String uri = "android.resource://" + getPackageName() + "/" + R.raw.base;
    // 本地视频
    // videoView.setVideoPath(path);
    // 网络视频
    // videoView.setVideoURI(Uri.parse("http://www.runoob.com/try/demo_source/movie.mp4"));
    videoView.setVideoURI(Uri.parse(uri));
    mediaController = new MediaController(this);
    videoView.setMediaController(mediaController);
    mediaController.setMediaPlayer(videoView);
}
 
源代码14 项目: FoodOrdering   文件: Activity_VideoSurveillance.java
private void initView() {
    pg=new ProgressDialog(Activity_VideoSurveillance.this);
    pg.setMessage("缓冲中...");
    pg.show();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    TextView toolbarText = (TextView) findViewById(R.id.toolbar_text);
    toolbarText.setText("视频监控");
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (!Util.checkNetwork(this)) {
        return;
    }
    videoViewVideo = (VideoView) findViewById(R.id.videoViewVideo);

    try {
        //设置视频控制器
        MediaController mediacontroller = new MediaController(Activity_VideoSurveillance.this);
        mediacontroller.setAnchorView(videoViewVideo);
        videoViewVideo.setMediaController(mediacontroller);
        //视频来源
        videoViewVideo.setVideoURI(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
    } catch (Exception e) {
        e.printStackTrace();
        pg.dismiss();
    }
    videoViewVideo.requestFocus();
    videoViewVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pg.dismiss();
            //开始播放视频
            videoViewVideo.start();
        }
    });
}
 
private void videoSet(VideoView video, Uri urinormal) {
    video.setVideoURI(urinormal);
    video.seekTo(1);
    controller = new MediaController(getActivity());
    videow = video;
    isvideo = true;
}
 
源代码16 项目: PictureSelector   文件: PictureVideoPlayActivity.java
@Override
protected void initWidgets() {
    super.initWidgets();
    videoPath = getIntent().getStringExtra(PictureConfig.EXTRA_VIDEO_PATH);
    boolean isExternalPreview = getIntent().getBooleanExtra
            (PictureConfig.EXTRA_PREVIEW_VIDEO, false);
    if (TextUtils.isEmpty(videoPath)) {
        LocalMedia media = getIntent().getParcelableExtra(PictureConfig.EXTRA_MEDIA_KEY);
        if (media == null || TextUtils.isEmpty(media.getPath())) {
            finish();
            return;
        }
        videoPath = media.getPath();
    }
    if (TextUtils.isEmpty(videoPath)) {
        closeActivity();
        return;
    }
    ibLeftBack = findViewById(R.id.pictureLeftBack);
    mVideoView = findViewById(R.id.video_view);
    tvConfirm = findViewById(R.id.tv_confirm);
    mVideoView.setBackgroundColor(Color.BLACK);
    iv_play = findViewById(R.id.iv_play);
    mMediaController = new MediaController(this);
    mVideoView.setOnCompletionListener(this);
    mVideoView.setOnPreparedListener(this);
    mVideoView.setMediaController(mMediaController);
    ibLeftBack.setOnClickListener(this);
    iv_play.setOnClickListener(this);
    tvConfirm.setOnClickListener(this);

    tvConfirm.setVisibility(config.selectionMode
            == PictureConfig.SINGLE
            && config.enPreviewVideo && !isExternalPreview ? View.VISIBLE : View.GONE);
}
 
源代码17 项目: ucar-weex-core   文件: WXVideoView.java
private synchronized void createVideoView() {
  if(mVideoView != null){
    return;
  }
  Context context = getContext();
  WXVideoView video = new WXVideoView(context);
  FrameLayout.LayoutParams videoLayoutParams =
      new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.MATCH_PARENT);
  videoLayoutParams.gravity = Gravity.CENTER;
  video.setLayoutParams(videoLayoutParams);
  addView(video, 0);//first child
  video.setOnErrorListener(mOnErrorListener);
  video.setOnPreparedListener(mOnPreparedListener);
  video.setOnCompletionListener(mOnCompletionListener);
  video.setOnVideoPauseListener(mVideoPlayListener);
  MediaController controller = new MediaController(context);
  controller.setAnchorView(this);
  video.setMediaController(controller);
  controller.setMediaPlayer(video);

  mMediaController = controller;
  mVideoView = video;

  if(mUri != null) {
    setVideoURI(mUri);
  }
}
 
源代码18 项目: BBSSDK-for-Android   文件: PageVideoViewer.java
protected void loadContent(String filePath, String extension, LoadContentListener loadContentListener) {
	//显示使用其它应用打开的入口,并使用videoView打开
	try {
		Uri uri = Uri.fromFile(new File(filePath));
		videoView.setMediaController(new MediaController(getContext()));
		videoView.setVideoURI(uri);
		videoView.requestFocus();
		loadContentListener.onLoadFinished(true);
	} catch (Throwable t) {
		loadContentListener.onLoadFinished(false);
	}
}
 
源代码19 项目: Slide   文件: MediaVideoViewOld.java
public void setMediaController(MediaController controller) {
    if (mMediaController != null) {
        mMediaController.hide();
    }
    mMediaController = controller;
    attachMediaController();
}
 
源代码20 项目: letv   文件: VideoViewH264LeMobile.java
public void setMediaController(MediaController controller) {
    if (this.mMediaController != null) {
        this.mMediaController.hide();
    }
    this.mMediaController = controller;
    attachMediaController();
}
 
源代码21 项目: letv   文件: VideoViewH264m3u8_4D.java
public void setMediaController(MediaController controller) {
    if (this.mMediaController != null) {
        this.mMediaController.hide();
    }
    this.mMediaController = controller;
    attachMediaController();
}
 
源代码22 项目: letv   文件: VideoViewH264LeMobile_4D.java
public void setMediaController(MediaController controller) {
    if (this.mMediaController != null) {
        this.mMediaController.hide();
    }
    this.mMediaController = controller;
    attachMediaController();
}
 
源代码23 项目: letv   文件: VideoViewH264mp4_4D.java
public void setMediaController(MediaController controller) {
    if (this.mMediaController != null) {
        this.mMediaController.hide();
    }
    this.mMediaController = controller;
    attachMediaController();
}
 
源代码24 项目: ShareBox   文件: VideoFragment.java
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mMediaController = new MediaController(getContext());
    mVideoView = (VideoView) view.findViewById(R.id.video);
    mVideoView.setVideoPath(mVideoUrl);
    mVideoView.setMediaController(mMediaController);
    mVideoView.requestFocus();
}
 
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	// Get a reference to the VideoView
	
	mVideoView = (VideoView) findViewById(R.id.videoViewer);

	// Add a Media controller to allow forward/reverse/pause/resume 
	
	final MediaController mMediaController = new MediaController(
			AudioVideoVideoPlayActivity.this, true);
	
	mMediaController.setEnabled(false);

	mVideoView.setMediaController(mMediaController);
	
	mVideoView
			.setVideoURI(Uri
					.parse("android.resource://course.examples.AudioVideo.VideoPlay/raw/moon"));
	
	// Add an OnPreparedListener to enable the MediaController once the video is ready
	mVideoView.setOnPreparedListener(new OnPreparedListener() {

		@Override
		public void onPrepared(MediaPlayer mp) {
			mMediaController.setEnabled(true);
		}
	});
}
 
源代码26 项目: Spectaculum   文件: SpectaculumDemoBaseActivity.java
/**
 * Creates a media controller and attaches it to the activity.
 * This method is for activities that contain a video player.
 * @param mediaPlayerControl the control interface, e.g. a video view
 */
public void initMediaController(MediaController.MediaPlayerControl mediaPlayerControl) {
    mMediaController = new MediaController(this);
    mMediaController.setAnchorView(findViewById(R.id.container));
    mMediaController.setMediaPlayer(mediaPlayerControl);
    mMediaController.setEnabled(false);
}
 
源代码27 项目: ml-authentication   文件: VideoActivity.java
@Override
    protected void onStart() {
        Log.i(getClass().getName(), "onStart");
        super.onStart();

        Bundle extras = getIntent().getExtras();
        long videoId = extras.getLong(EXTRA_KEY_VIDEO_ID);
        Log.i(getClass().getName(), "videoId: " + videoId);

        Video video = videoDao.load(videoId);
        File videoFile = MultimediaHelper.getFile(video);
        Log.i(getClass().getName(), "videoFile: " + videoFile);

        videoView.setVideoPath(videoFile.getAbsolutePath());
        videoView.setMediaController(new MediaController(this));
        videoView.start();

        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                Log.i(getClass().getName(), "onCompletion");

                // TODO: track VideoCompletedEvent

                Intent loadingIntent = new Intent(getApplicationContext(), LoadingActivity.class);
//                String letter = "a"; // TODO: fetch dynamically
//                loadingIntent.putExtra(LoadingActivity.EXTRA_KEY_LETTER, letter);
                startActivity(loadingIntent);

                finish();
            }
        });
    }
 
源代码28 项目: deltachat-android   文件: VideoPlayer.java
private void initializeVideoViewControls(@NonNull VideoView videoView) {
  MediaController mediaController = new MediaController(getContext());
  mediaController.setAnchorView(videoView);
  mediaController.setMediaPlayer(videoView);

  videoView.setMediaController(mediaController);
}
 
源代码29 项目: texturevideoview   文件: TextureVideoView.java
public void setMediaController(MediaController controller) {
    if (mMediaController != null) {
        mMediaController.hide();
    }
    mMediaController = controller;
    attachMediaController();
}
 
源代码30 项目: GifAssistant   文件: VideoView.java
public void setMediaController(MediaController controller) {
    if (mMediaController != null) {
        mMediaController.hide();
    }
    mMediaController = controller;
    attachMediaController();
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 同包方法