@ Override public void play ( final String uri ) { Log . d ( TAG , "Start playing " + uri ) ; notifyVideoUnavailable ( REASON_BUFFERING ) ; isWeb = false ; TvInputPlayer . Callback callback = new TvInputPlayer . Callback ( ) { @ Override public void onPrepared ( ) { notifyVideoAvailable ( ) ; setOverlayEnabled ( false ) ; } @ Override public void onPlayerStateChanged ( boolean playWhenReady , int state ) { } @ Override public void onPlayWhenReadyCommitted ( ) { } @ Override public void onPlayerError ( ExoPlaybackException e ) { Log . e ( TAG , e . getMessage ( ) + "" ) ; if ( e . getMessage ( ) . contains ( "Extractor" ) ) { Log . d ( TAG , "Cannot play the stream, try loading it as a website" ) ; Log . d ( TAG , "Open " + uri ) ; //Pretend this is a website loadUrl ( uri ) ; isWeb = true ; setOverlayEnabled ( false ) ; notifyVideoAvailable ( ) ; isWeb = true ; setOverlayEnabled ( false ) ; setOverlayEnabled ( true ) ; isWeb = true ; } } @ Override public void onDrawnToSurface ( Surface surface ) { } @ Override public void onText ( String text ) { } } ; try { tvInputPlayer . removeCallback ( callback ) ; } catch ( NullPointerException e ) { Log . w ( TAG , "exoplayer.removeCallback error " + e . getMessage ( ) ) ; } tvInputPlayer . addCallback ( callback ) ; tvInputPlayer . setSurface ( mSurface ) ; Log . d ( TAG , "Play " + uri + "; " + uri . indexOf ( "file:///" ) ) ; if ( uri . contains ( "file:///" ) ) { Log . i ( TAG , "Is a local file" ) ; //Find appropriate extractor DataSource dataSource = new DefaultUriDataSource ( getApplicationContext ( ) , TvInputPlayer . getUserAgent ( getApplicationContext ( ) ) ) ; ExtractorSampleSource extractorSampleSource = new ExtractorSampleSource ( Uri . parse ( uri ) , dataSource , new DefaultAllocator ( TvInputPlayer . BUFFER_SEGMENT_SIZE ) , TvInputPlayer . BUFFER_SEGMENTS * TvInputPlayer . BUFFER_SEGMENT_SIZE , new Mp4Extractor ( ) , new Mp3Extractor ( ) ) ; TrackRenderer audio = new MediaCodecAudioTrackRenderer ( extractorSampleSource , MediaCodecSelector . DEFAULT ) ; TrackRenderer video = new MediaCodecVideoTrackRenderer ( getApplicationContext ( ) , extractorSampleSource , MediaCodecSelector . DEFAULT , MediaCodec . VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING ) ; tvInputPlayer . prepare ( audio , video , new DummyTrackRenderer ( ) ) ; } else { try { tvInputPlayer . prepare ( getApplicationContext ( ) , Uri . parse ( uri ) , TvInputPlayer . SOURCE_TYPE_HLS ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } tvInputPlayer . setPlayWhenReady ( true ) ; }
Tries to load a video file . If one cannot be played it will be interpreted as a website and begin to load it in a web browser