@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mIsPrepared && keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_ENDCALL && mMediaPlayer != null && mMediaController != null) { if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } else { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP && mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } else { toggleMediaControlsVisiblity(); } } return super.onKeyDown(keyCode, event); }
private void h() { if (!B.p()) { l.e(k, "changeToCastMode error, chromecast is not connected"); return; } if (p != null) { p.hide(); } m(); A = 1; o.setVisibility(0); if (q == null) { q = new kk(this, this); if (r == null) { r = new kt(this); B.a(r); B.a(r); B.a(r); } q.setMediaPlayer(r); q.setAnchorView(o); } ((ImageView)z.findViewById(2131624054)).setImageResource(2130838531); if ((B.r() > 0) && (B.r() != 2)) { b.setVisibility(0); } J.sendMessageDelayed(J.obtainMessage(5), 1000L); }
public void onPrepared(MediaPlayer mp) { mCurrentState = STATE_PREPARED; // modify by lxj // Get the capabilities of the player for this stream // Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL, // MediaPlayer.BYPASS_METADATA_FILTER); // // if (data != null) { // mCanPause = !data.has(Metadata.PAUSE_AVAILABLE) // || data.getBoolean(Metadata.PAUSE_AVAILABLE); // mCanSeekBack = !data.has(Metadata.SEEK_BACKWARD_AVAILABLE) // || data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE); // mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE) // || data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE); // } else { // mCanPause = mCanSeekBack = mCanSeekForward = true; // } mCanPause = mCanSeekBack = mCanSeekForward = true; if (mOnPreparedListener != null) { mOnPreparedListener.onPrepared(mMediaPlayer); } if (mMediaController != null) { mMediaController.setEnabled(true); } mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call if (seekToPosition != 0) { seekTo(seekToPosition); } if (mVideoWidth != 0 && mVideoHeight != 0) { // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight); getHolder().setFixedSize(mVideoWidth, mVideoHeight); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { // We didn't actually change the size (it was already at the size // we need), so we won't get a "surface changed" callback, so // start the video here instead of in the callback. if (mTargetState == STATE_PLAYING) { start(); if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) { // Show the media controls when we're paused into a video and make 'em stick. mMediaController.show(0); } } } } else { // We don't know the video size yet, but should start anyway. // The video size might be reported to us later. if (mTargetState == STATE_PLAYING) { start(); } } }
private void preparePlayer(boolean playWhenReady) { if (player == null) { player = new DemoPlayer(getRendererBuilder()); player.addListener(this); player.setCaptionListener(this); player.setMetadataListener(this); player.seekTo(playerPosition); playerNeedsPrepare = true; mediaController.setMediaPlayer(player.getPlayerControl()); mediaController.setEnabled(true); eventLogger = new EventLogger(); eventLogger.startSession(); player.addListener(eventLogger); player.setInfoListener(eventLogger); player.setInternalErrorListener(eventLogger); debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper.start(); } if (playerNeedsPrepare) { player.prepare(); playerNeedsPrepare = false; updateButtonVisibilities(); } player.setSurface(surfaceView.getHolder().getSurface()); player.setPlayWhenReady(playWhenReady); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vdo); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); final VideoView video1 = (VideoView) findViewById(R.id.videoView1); video1.setVideoPath(th); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(video1); video1.setMediaController(mediaController); Toast.makeText(getBaseContext(), "รอสักครู่...", Toast.LENGTH_SHORT) .show(); // text preloading.. video1.setOnPreparedListener( new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { Log.i(TAG, "Duration = " + video1.getDuration()); } }); video1.requestFocus(); // comment1 video1.start(); // finish(); //comment }
private void toggleMediaControlsVisiblity() { if (mMediaController.isShowing()) { mMediaController.hide(); } else { mMediaController.show(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); VideoView videoView = (VideoView) findViewById(R.id.videoView); videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.demovideo); android.widget.MediaController mediaController = new android.widget.MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); videoView.start(); /* FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); */ }
@Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fr_less_15_c, container, false); ImageButton button = (ImageButton) view.findViewById(R.id.playVideo); videoView = (VideoView) view.findViewById(R.id.less_15_c); MediaController mController = new MediaController(getActivity()); mController.setAnchorView(videoView); Uri videoUri = Uri.parse("android.resource://com.example.dell.learnerintermediate/raw/less_15_c"); videoView.setMediaController(mController); videoView.setVideoURI(videoUri); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { videoView.start(); } }); return view; }
@Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); mediacontroller.setMediaPlayer(this); mediacontroller.setAnchorView(findViewById(R.id.surfaceView)); mediacontroller.show(); }
private void toggleControlsVisibility() { if (mediaController.isShowing()) { mediaController.hide(); // debugRootView.setVisibility(View.GONE); } else { showControls(); } }
private void attachMediaController() { if (mMediaPlayer != null && mMediaController != null) { mMediaController.setMediaPlayer(this); View anchorView = this.getParent() instanceof View ? (View) this.getParent() : this; mMediaController.setAnchorView(anchorView); mMediaController.setEnabled(mIsPrepared); } }
// ----------------start play video ---------------- void playVideo() { videoView = (VideoView) findViewById(R.id.videoView); videoView.setVideoPath( "http://media.karaokecuatui.vn/mv/AnhVanYeuEmNhuNgayDauTien_CaoThaiSon.mp4"); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setOnCompletionListener(completionlistener); videoView.setMediaController(mediaController); videoView.start(); }
@Override protected void onPostExecute(Uri pResult) { super.onPostExecute(pResult); try { if (isCancelled()) return; if (pResult == null) { throw new RuntimeException("Invalid NULL Url."); } mVideoView.setVideoURI(pResult); if (isCancelled()) return; // TODO: add listeners for finish of video mVideoView.setOnCompletionListener( new OnCompletionListener() { public void onCompletion(MediaPlayer pMp) { if (isCancelled()) return; OpenYouTubePlayerActivity.this.finish(); } }); if (isCancelled()) return; final MediaController lMediaController = new MediaController(OpenYouTubePlayerActivity.this); mVideoView.setMediaController(lMediaController); lMediaController.show(0); // mVideoView.setKeepScreenOn(true); mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer pMp) { if (isCancelled()) return; OpenYouTubePlayerActivity.this.mProgressBar.setVisibility(View.GONE); OpenYouTubePlayerActivity.this.mProgressMessage.setVisibility(View.GONE); } }); if (isCancelled()) return; mVideoView.requestFocus(); mVideoView.start(); } catch (Exception e) { Log.e(this.getClass().getSimpleName(), "Error playing video!" + pResult, e); if (!mShowedError) { showErrorAlert(); } } }
@Override public void onResume() { super.onResume(); mPlayer = ExoPlayer.Factory.newInstance(2, 1000, 5000); mPlayer.addListener(this); mPlayer.seekTo(mPlayerPosition); mMediaController.setMediaPlayer(new PlayerControl(mPlayer)); mMediaController.setEnabled(true); mCallback = new RendererBuilderCallback(); mBuilder.buildRenderers(mCallback); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu__usuario__uno); final VideoView videoView = (VideoView) findViewById(R.id.webView); videoView.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4"); videoView.start(); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); videoView.start(); }
@Override public void onPrepared(MediaPlayer mediaPlayer) { mediaController.setMediaPlayer(this); mediaController.setAnchorView(findViewById(R.id.main_audio_view)); handler.post( new Runnable() { public void run() { mediaController.setEnabled(true); mediaController.show(); } }); }
public void onPrepared(MediaPlayer mp) { // briefly show the mediacontroller mIsPrepared = true; if (mOnPreparedListener != null) { mOnPreparedListener.onPrepared(mMediaPlayer); } if (mMediaController != null) { mMediaController.setEnabled(true); } mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); if (mVideoWidth != 0 && mVideoHeight != 0) { // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ // mVideoHeight); getHolder().setFixedSize(mVideoWidth, mVideoHeight); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { // We didn't actually change the size (it was already at the // size // we need), so we won't get a "surface changed" callback, // so // start the video here instead of in the callback. if (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared = 0; } if (mStartWhenPrepared) { mMediaPlayer.start(); mStartWhenPrepared = false; if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) { // Show the media controls when we're paused into a // video and make 'em stick. mMediaController.show(0); } } } } else { // We don't know the video size yet, but should start anyway. // The video size might be reported to us later. if (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared = 0; } if (mStartWhenPrepared) { mMediaPlayer.start(); mStartWhenPrepared = false; } } }
@Override public void onStop() { super.onStop(); if (mMenu != null) { mMenu.removeItem(R.id.action_share); mMenu.removeItem(R.id.action_favorite); mMenu.removeItem(R.id.action_unfavorite); mMenu = null; } if (mMediaController != null && mMediaController.isShowing()) { mMediaController.hide(); } }
public void invalidateView() { final boolean show = controller != null && controller.isShowing(); if (DEBUG) { Log.d(TAG, "Invalidate view, controller showing: " + show); } if (show) { controller.hide(); // XXX don't know when we have new dimensions, it should be done with something like // requestLayout final long delay = 250; handler.removeCallbacks(showController); handler.postDelayed(showController, delay); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.video_alert_dialog); ok = (Button) findViewById(R.id.btn_ok_video); MediaController mediaController = new MediaController(getContext()); Log.i("Video Uri", url.toString()); vv = (VideoView) findViewById(R.id.vid_dialog); mediaController.setAnchorView(vv); vv.setVideoURI(url); vv.start(); ok.setOnClickListener(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_canciones); tituloView = (TextView) findViewById(R.id.texto_canciones); server = new BusinessCanciones(php); // Creo videoview solo 1 vez video = new VideoView(this); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); video.setLayoutParams(params); controller = new MediaController(this) { /*@Override public void hide() {}*/ @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { finish(); } return super.dispatchKeyEvent(event); } }; controller.setAnchorView(video); video.setMediaController(controller); // Cargo la primera cancion siguienteCancion(); }
public void setMediaController(MediaController controller) { if (mMediaController != null) { mMediaController.hide(); } mMediaController = controller; attachMediaController(); }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mMediaController = new MediaController(view.getContext()); mMediaController.setAnchorView(view); mSurfaceView.getHolder().addCallback(this); }
@Override protected void onStop() { super.onStop(); mediaController.hide(); mediaPlayer.stop(); mediaPlayer.release(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_avplayer); mVideoView = (VideoView) findViewById(R.id.videoView1); Intent i = getIntent(); trackList = i.getParcelableArrayListExtra(Track.klass); currentPlaylist = new Playlist(trackList, i.getIntExtra("pos", 0)); mediaPlayer = new MediaPlayer(); mediaPlayer.setOnPreparedListener(this); mediaController = new MediaController(this); mVideoView.setMediaController(mediaController); mVideoView.setVisibility(VideoView.INVISIBLE); // set controls for next and previous mediaController.setPrevNextListeners( new View.OnClickListener() { @Override public void onClick(View next) { prepareToStart(currentPlaylist.getNext()); } }, new View.OnClickListener() { @Override public void onClick(View prev) { prepareToStart(currentPlaylist.getPrevious()); } }); prepareToStart(currentPlaylist.getCurrent()); }
private void prepareToStart(Track dataSource) { try { if (dataSource.isVideo()) { mediaController.setMediaPlayer(mVideoView); mVideoView.setVisibility(VideoView.VISIBLE); mVideoView.setVideoPath(dataSource.getPath()); mVideoView.start(); } else { mediaPlayer.reset(); mVideoView.setVisibility(VideoView.INVISIBLE); mediaPlayer.setDataSource(dataSource.getPath()); mediaPlayer.prepare(); mediaPlayer.start(); } ((TextView) findViewById(R.id.now_playing_text)) .setText(currentPlaylist.getCurrent().getTitle()); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public boolean onTouchEvent(MotionEvent event) { if (mIsMediaReadyToBePlayed) { mMediaController.show(); } return false; }
public void siguienteCancion() { if (!server.finJuego()) { new ProgressTask<Canciones>(this) { @Override protected Canciones work() throws Exception { cancion = server.getCanciones(); return cancion; } @Override protected void onFinish(Canciones cancion) { tituloView.setText(cancion.getTitulo()); String urlCancion = cancion.getVideo(); playVideo(urlCancion); } }.execute(); } else { LinearLayout layoutEntero = (LinearLayout) findViewById(R.id.layout_canciones_entero); layoutEntero.removeAllViews(); controller.hide(); TextView txNuevo = new TextView(this); txNuevo.setText("AMAIERA"); txNuevo.setTextColor(Color.WHITE); txNuevo.setGravity(Gravity.CENTER); txNuevo.setTextSize(70); layoutEntero.addView(txNuevo); } }
@Override public void hide() { if (mVideoView != null) { mVideoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); } mMediaController.hide(); }
@Override public void show() { mMediaController.show(); if (mVideoView != null) { mVideoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } }