2016-02-08 148 views
1

我使用下面的代碼使用EXOPlayer播放視頻,但不播放。在EXOPlayer中播放視頻

視頻格式爲mp4格式。我在哪裏出錯了? 它顯示錯誤 -

com.google.android.exoplayer.ExoPlaybackException: java.io.IOException: Failed to instantiate extractor. 

代碼 -

loadvideo("res:/" + R.raw.samplevider); 


private void loadvideo(String path) { 
    player = ExoPlayer.Factory.newInstance(2, 1000, 5000); 
    Uri uri = Uri.parse(path); 
    sampleSource = new FrameworkSampleSource(getActivity().getApplicationContext(), uri, null); 
    // 1. Instantiate the player. 
    // 2. Construct renderers. 
    videoRenderer = new MediaCodecVideoTrackRenderer(getActivity().getApplicationContext(),sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING); 
    audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,MediaCodecSelector.DEFAULT); 
    // 3. Inject the renderers through prepare. 
    player.prepare(videoRenderer, audioRenderer); 
    // 4. Pass the surface to the video renderer. 
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surfaceView.getHolder().getSurface()); 
    // 5. Start playback. 
    player.setPlayWhenReady(true); 
} 

回答

0

試試這個:

 private static final int BUFFER_SEGMENT_SIZE = 64 * 1024; 
     private static final int BUFFER_SEGMENT_COUNT = 256; 
     private static final int RENDERER_COUNT = 3; 

     Uri uri = Uri.parse(getAVideoUri()); 

     Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE); 

     DataSource dataSource = new DefaultUriDataSource(this, null, getUserAgent(this, "ExoPlayerExample")); 

     ExtractorSampleSource sampleSource = new ExtractorSampleSource(
        uri, dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE); 

     MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(
        this, sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); 
     MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(
        sampleSource, MediaCodecSelector.DEFAULT); 
     player = ExoPlayer.Factory.newInstance(RENDERER_COUNT); 

     player.prepare(videoRenderer, audioRenderer, secondAudioRenderer); 
     player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surfaceView.getHolder().getSurface()); 
     player.setPlayWhenReady(true); 
+0

它也不工作。該問題與文件編碼有關。 –

+0

@LostPuppy你有解決方案嗎?請幫助我getDuration()爲ExoPlayer並看看http://stackoverflow.com/questions/39777975/not-able-to-get-getduration-for-aac-file-using-exoplayer –