media-widget/src/main/java/androidx/media/widget/impl/VideoView2ImplBase.java
private void openVideo(DataSourceDesc dsd) {
        Uri uri = dsd.getUri();
        Map<String, String> headers = dsd.getUriHeaders();
        resetPlayer();
        if (isRemotePlayback()) {
            // TODO: b/77556429
            mRoutePlayer.openVideo(uri);
            return;
        }

        try {
            Log.d(TAG, "openVideo(): creating new MediaPlayer instance.");
            mMediaPlayer = MediaPlayer2.create();
            mSurfaceView.setMediaPlayer(mMediaPlayer);
            mTextureView.setMediaPlayer(mMediaPlayer);
            mCurrentView.assignSurfaceToMediaPlayer(mMediaPlayer);

            final Context context = mInstance.getContext();
            mSubtitleController = new SubtitleController(context);
            mSubtitleController.registerRenderer(new ClosedCaptionRenderer(context));
            mSubtitleController.setAnchor((SubtitleController.Anchor) mSubtitleView);
            Executor executor = new Executor() {
                @Override
                public void execute(Runnable runnable) {
                    runnable.run();
                }
            };
            mMediaPlayer.setMediaPlayer2EventCallback(executor, mMediaPlayer2Callback);

            mCurrentBufferPercentage = -1;
            mMediaPlayer.setDataSource(dsd);
            mMediaPlayer.setAudioAttributes(mAudioAttributes);
            // we don't set the target state here either, but preserve the
            // target state that was there before.
            mCurrentState = STATE_PREPARING;
            mMediaPlayer.prepare();

            // Save file name as title since the file may not have a title Metadata.
            mTitle = uri.getPath();
            String scheme = uri.getScheme();
            if (scheme != null && scheme.equals("file")) {
                mTitle = uri.getLastPathSegment();
                mRetriever = new MediaMetadataRetriever();
                mRetriever.setDataSource(context, uri);
            }

            if (DEBUG) {
                Log.d(TAG, "openVideo(). mCurrentState=" + mCurrentState
                        + ", mTargetState=" + mTargetState);
            }
        } catch (IllegalArgumentException ex) {
            Log.w(TAG, "Unable to open content: " + uri, ex);
            mCurrentState = STATE_ERROR;
            mTargetState = STATE_ERROR;
            mMediaPlayer2Callback.onError(mMediaPlayer, dsd,
                    MediaPlayer2.MEDIA_ERROR_UNKNOWN, MediaPlayer2.MEDIA_ERROR_IO);
        }
    }
// Creates a MediaPlayer instance and prepare playback.
Creates a MediaPlayer instance and prepare playback.
Creates a MediaPlayer instance and prepare playback .
private void openVideo(DataSourceDesc dsd) {
        Uri uri = dsd.getUri();
        Map<String, String> headers = dsd.getUriHeaders();
        resetPlayer();
        if (isRemotePlayback()) {
            mRoutePlayer.openVideo(uri);
            return;
        }
        try {
            Log.d(TAG, "openVideo(): creating new MediaPlayer instance.");
            mMediaPlayer = MediaPlayer2.create();
            mSurfaceView.setMediaPlayer(mMediaPlayer);
            mTextureView.setMediaPlayer(mMediaPlayer);
            mCurrentView.assignSurfaceToMediaPlayer(mMediaPlayer);
            final Context context = mInstance.getContext();
            mSubtitleController = new SubtitleController(context);
            mSubtitleController.registerRenderer(new ClosedCaptionRenderer(context));
            mSubtitleController.setAnchor((SubtitleController.Anchor) mSubtitleView);
            Executor executor = new Executor() {
                @Override
                public void execute(Runnable runnable) {
                    runnable.run();
                }
            };
            mMediaPlayer.setMediaPlayer2EventCallback(executor, mMediaPlayer2Callback);
            mCurrentBufferPercentage = -1;
            mMediaPlayer.setDataSource(dsd);
            mMediaPlayer.setAudioAttributes(mAudioAttributes);
            mCurrentState = STATE_PREPARING;
            mMediaPlayer.prepare();
            mTitle = uri.getPath();
            String scheme = uri.getScheme();
            if (scheme != null && scheme.equals("file")) {
                mTitle = uri.getLastPathSegment();
                mRetriever = new MediaMetadataRetriever();
                mRetriever.setDataSource(context, uri);
            }
            if (DEBUG) {
                Log.d(TAG, "openVideo(). mCurrentState=" + mCurrentState
                        + ", mTargetState=" + mTargetState);
            }
        } catch (IllegalArgumentException ex) {
            Log.w(TAG, "Unable to open content: " + uri, ex);
            mCurrentState = STATE_ERROR;
            mTargetState = STATE_ERROR;
            mMediaPlayer2Callback.onError(mMediaPlayer, dsd,
                    MediaPlayer2.MEDIA_ERROR_UNKNOWN, MediaPlayer2.MEDIA_ERROR_IO);
        }
    }
private void openVideo ( DataSourceDesc dsd ) { Uri uri = dsd . getUri ( ) ; Map < String , String > headers = dsd . getUriHeaders ( ) ; resetPlayer ( ) ; if ( isRemotePlayback ( ) ) { mRoutePlayer . openVideo ( uri ) ; return ; } try { Log . d ( TAG , "openVideo(): creating new MediaPlayer instance." ) ; mMediaPlayer = MediaPlayer2 . create ( ) ; mSurfaceView . setMediaPlayer ( mMediaPlayer ) ; mTextureView . setMediaPlayer ( mMediaPlayer ) ; mCurrentView . assignSurfaceToMediaPlayer ( mMediaPlayer ) ; final Context context = mInstance . getContext ( ) ; mSubtitleController = new SubtitleController ( context ) ; mSubtitleController . registerRenderer ( new ClosedCaptionRenderer ( context ) ) ; mSubtitleController . setAnchor ( ( SubtitleController . Anchor ) mSubtitleView ) ; Executor executor = new Executor ( ) { @ Override public void execute ( Runnable runnable ) { runnable . run ( ) ; } } ; mMediaPlayer . setMediaPlayer2EventCallback ( executor , mMediaPlayer2Callback ) ; mCurrentBufferPercentage = - 1 ; mMediaPlayer . setDataSource ( dsd ) ; mMediaPlayer . setAudioAttributes ( mAudioAttributes ) ; mCurrentState = STATE_PREPARING ; mMediaPlayer . prepare ( ) ; mTitle = uri . getPath ( ) ; String scheme = uri . getScheme ( ) ; if ( scheme != null && scheme . equals ( "file" ) ) { mTitle = uri . getLastPathSegment ( ) ; mRetriever = new MediaMetadataRetriever ( ) ; mRetriever . setDataSource ( context , uri ) ; } if ( DEBUG ) { Log . d ( TAG , "openVideo(). mCurrentState=" + mCurrentState + ", mTargetState=" + mTargetState ) ; } } catch ( IllegalArgumentException ex ) { Log . w ( TAG , "Unable to open content: " + uri , ex ) ; mCurrentState = STATE_ERROR ; mTargetState = STATE_ERROR ; mMediaPlayer2Callback . onError ( mMediaPlayer , dsd , MediaPlayer2 . MEDIA_ERROR_UNKNOWN , MediaPlayer2 . MEDIA_ERROR_IO ) ; } }
Creates a MediaPlayer instance and prepare playback.
Creates a MediaPlayer instance and prepare playback .
// TODO: b/77556429 // we don't set the target state here either, but preserve the // target state that was there before. // Save file name as title since the file may not have a title Metadata.