Api has a token header that i need to set but the video is not encrypted. I have two questions: How can i play .mpg,.mpeg,.3gp,.mov and other files from disk with exoplayer? How can i set headers with exoplayer and stream mp4 video from url?
Figured out the answer:
DefaultHttpDataSource source = new DefaultHttpDataSource(userAgent, null);
source.setRequestProperty("Authorization", "your auth code");
source.setRequestProperty("Accept", "...");
ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, source, extractor, 2,
BUFFER_SIZE);
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
null, true, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING, 5000, null, player.getMainHandler(),
player, 50);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
null, true, player.getMainHandler(), player);
// (1) Create method returns 'DataSource.Factory'
public DataSource.Factory headers() {
Map<String, String> headersMap = new HashMap<>();
headersMap.put("iid", "aaa123 ");
headersMap.put("version", "1.4");
headersMap.put("agent", "phone");
headersMap.put("token", "dfdf4f4yt5yf5fh4f5");
return new DefaultHttpDataSource.Factory().setDefaultRequestProperties(headersMap);
}
// (2) Add headers() method call to the player
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context)
.setMediaSourceFactory(new
DefaultMediaSourceFactory(headers()))
.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With