@Override public void setSurface(Surface surface) { if (mediaPlayer != null) mediaPlayer.setSurface(surface); }
@SuppressLint("NewApi") private void playVideo(SurfaceTexture surfaceTexture) { doCleanUp(); try { path = ""; if (path == "") { // Tell the user to provide a media file URL. Toast.makeText( MediaPlayerDemo_setSurface.this, "Please edit MediaPlayerDemo_setSurface Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", Toast.LENGTH_LONG).show(); return; } // Create a new media player and set the listeners mMediaPlayer = new MediaPlayer(this, true); mMediaPlayer.setDataSource(path); if (surf == null) { surf = new Surface (surfaceTexture); } mMediaPlayer.setSurface(surf); mMediaPlayer.prepareAsync(); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnPreparedListener(this); setVolumeControlStream(AudioManager.STREAM_MUSIC); } catch (Exception e) { Log.e(TAG, "error: " + e.getMessage(), e); } }