@Override public void buildRenderers(ExoPlayerHelper player) { Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE); // Build the video and audio renderers. Extractor webmExtractor = new WebmExtractor(); Extractor mp4Extractor = new Mp4Extractor(); DataSource dataSource = new FileDataSource(); ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, webmExtractor, mp4Extractor); MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, player.getMainHandler(), player, 50); MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource, MediaCodecSelector.DEFAULT, null, true, player.getMainHandler(), player); TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player, player.getMainHandler().getLooper()); // Invoke the callback. TrackRenderer[] renderers = new TrackRenderer[ExoPlayerHelper.RENDERER_COUNT]; renderers[ExoPlayerHelper.TYPE_VIDEO] = videoRenderer; renderers[ExoPlayerHelper.TYPE_AUDIO] = audioRenderer; renderers[ExoPlayerHelper.TYPE_TEXT] = textRenderer; player.onRenderers(renderers, null); }
private void initRender(String url){ Uri uri = Uri.parse(url); OkHttpDataSource okHttpDataSource = new OkHttpDataSource(RetrofitClient.getOkHttpClient(getContext()) ,userAgent , null); okHttpDataSource.setRequestProperty("Referer", RetrofitClient.URL_REFERER); ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, okHttpDataSource, new DefaultAllocator(5 * K), 5 * K * K, new Mp4Extractor()); mVideoRender = new MediaCodecVideoTrackRenderer(getContext() , sampleSource , MediaCodecSelector.DEFAULT , MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); mAudioRender = new MediaCodecAudioTrackRenderer(sampleSource , MediaCodecSelector.DEFAULT); mPlayer.sendMessage(mVideoRender, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, mSurfaceView.getHolder().getSurface()); mPlayer.setPlayWhenReady(true); }