Java Code Examples for android.widget.MediaController#setMediaPlayer()
The following examples show how to use
android.widget.MediaController#setMediaPlayer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleVideoStream.java From cordova-plugin-streaming-media with MIT License | 8 votes |
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()); } }
Example 2
Source File: VideoViewActivity.java From MediaPlayer-Extended with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: VideoPlayer.java From fitness_Android with Apache License 2.0 | 5 votes |
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(); }
Example 4
Source File: VideoPlayer.java From fitness_Android with Apache License 2.0 | 5 votes |
@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); }
Example 5
Source File: WXVideoView.java From ucar-weex-core with Apache License 2.0 | 5 votes |
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); } }
Example 6
Source File: WXVideoView.java From weex-uikit with MIT License | 5 votes |
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); } }
Example 7
Source File: SpectaculumDemoBaseActivity.java From Spectaculum with Apache License 2.0 | 5 votes |
/** * 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); }
Example 8
Source File: VideoPlayer.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
private void initializeVideoViewControls(@NonNull VideoView videoView) { MediaController mediaController = new MediaController(getContext()); mediaController.setAnchorView(videoView); mediaController.setMediaPlayer(videoView); videoView.setMediaController(mediaController); }
Example 9
Source File: PlayerActivity.java From android-tv-leanback with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); 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); SampleSource sampleSource = new FrameworkSampleSource(this, Uri.parse(url), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
Example 10
Source File: PlayerActivity.java From android-tv-leanback with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); 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); SampleSource sampleSource = new FrameworkSampleSource(this, Uri.parse(url), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
Example 11
Source File: VideoPlayer.java From Silence with GNU General Public License v3.0 | 5 votes |
private void initializeVideoViewControls(@NonNull VideoView videoView) { MediaController mediaController = new MediaController(getContext()); mediaController.setAnchorView(videoView); mediaController.setMediaPlayer(videoView); videoView.setMediaController(mediaController); }
Example 12
Source File: PreviewVideoActivity.java From Cirrus_depricated with GNU General Public License v2.0 | 4 votes |
@Override protected void onAccountSet(boolean stateWasRecovered) { super.onAccountSet(stateWasRecovered); if (getAccount() != null) { OCFile file = getFile(); /// Validate handled file (first image to preview) if (file == null) { throw new IllegalStateException("Instanced with a NULL OCFile"); } if (!file.isVideo()) { throw new IllegalArgumentException("Non-video file passed as argument"); } file = getStorageManager().getFileById(file.getFileId()); if (file != null) { if (file.isDown()) { mVideoPlayer.setVideoURI(file.getStorageUri()); } else { // not working yet String url; try { url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath(); mVideoPlayer.setVideoURI(Uri.parse(url)); } catch (AccountNotFoundException e) { onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account); } } // create and prepare control panel for the user mMediaController = new MediaController(this); mMediaController.setMediaPlayer(mVideoPlayer); mMediaController.setAnchorView(mVideoPlayer); mVideoPlayer.setMediaController(mMediaController); } else { finish(); } } else { finish(); } }
Example 13
Source File: VitamioMedia.java From Vitamio-Cordova-Plugin with MIT License | 4 votes |
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) return; requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); extras = getIntent().getExtras(); // handle extras if (extras == null) { wrapItUp(RESULT_CANCELED, "Error: No options provided"); } else { if (extras.containsKey("isStreaming")) { isStreaming = extras.getBoolean("isStreaming"); } if (extras.containsKey("shouldAutoClose")) { mShouldAutoClose = extras.getBoolean("shouldAutoClose"); } mMediaType = extras.getString("type"); if (mMediaType == null) mMediaType = MEDIA_TYPE_VIDEO; mMediaPlayer = new MediaPlayer(this); mMediaController = new MediaController(this, !isStreaming); mMediaController.setMediaPlayer(this); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); setVolumeControlStream(AudioManager.STREAM_MUSIC); RelativeLayout relLayout = new RelativeLayout(this); if (extras.containsKey("bgColor")) { try { bgColor = Color.parseColor(extras.getString("bgColor")); } catch (Exception e) { Log.v(TAG, "Error parsing color"); Log.e(TAG, e.toString()); bgColor = DEFAULT_BG_COLOR; } } relLayout.setBackgroundColor(bgColor); RelativeLayout.LayoutParams relLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); relLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); mMediaView = new SurfaceView(this); mMediaView.setLayoutParams(relLayoutParam); relLayout.addView(mMediaView); mProgressBar = new ProgressBar(this); mProgressBar.setIndeterminate(true); mProgressBar.setVisibility(View.VISIBLE); RelativeLayout.LayoutParams pblp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); pblp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); mProgressBar.setLayoutParams(pblp); relLayout.addView(mProgressBar); mProgressBar.bringToFront(); mMediaController.setAnchorView(relLayout); mMediaController.setEnabled(true); if (mMediaType.equalsIgnoreCase(MEDIA_TYPE_AUDIO)) { mMediaView.setBackgroundColor(bgColor); if (extras.containsKey("bgImage")) { if (extras.containsKey("bgImageScaleType")) { String scaleType = extras.getString("bgImageScaleType"); if (scaleType.equalsIgnoreCase("fit")) { bgImageScaleType = ImageView.ScaleType.FIT_CENTER; } else if (scaleType.equalsIgnoreCase("stretch")) { bgImageScaleType = ImageView.ScaleType.FIT_XY; } else { bgImageScaleType = ImageView.ScaleType.CENTER; } } bgImage = new ImageView(this); new ImageLoadTask(extras.getString("bgImage"), this).execute(null, null); RelativeLayout.LayoutParams bgImageLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); bgImageLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT); bgImage.setLayoutParams(bgImageLayoutParam); bgImage.setScaleType(bgImageScaleType); relLayout.addView(bgImage); } } setContentView(relLayout, relLayoutParam); holder = mMediaView.getHolder(); holder.addCallback(this); holder.setFormat(PixelFormat.RGBA_8888); } }
Example 14
Source File: VideoPlayerActivity.java From AndroidDemoProjects with Apache License 2.0 | 4 votes |
protected void setupMediaController() { mMediaController = new MediaController( this ); mMediaController.setEnabled(true); mMediaController.show(); mMediaController.setMediaPlayer( mVideoView ); }