dheeraj9198 / Exoplayer-NanoHttpServer-SimplefileEncryption

Apache License 2.0
0 stars 1 forks source link

Playing encrypted mp4 file #1

Open AlirezaGhanbarinia opened 8 years ago

AlirezaGhanbarinia commented 8 years ago

Hi, First, thanks for your awesome tool.

Actually, I'm trying to play an encrypted local mp4 file with the codes provided below. Unfortunately, its not working and Exo can not play the video. Would you please help me on this matter? Appreciate any help.

,,,

 Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);

// Build the video and audio renderers.
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(), null);
DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);

Aes128DataSource aes128DataSource = new Aes128DataSource(dataSource, AES_KEY, AES_IV);

ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, aes128DataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, player.getMainHandler(), player, 50);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource, null, true, player.getMainHandler(), player, AudioCapabilities.getCapabilities(context));
TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player, player.getMainHandler().getLooper());

// Invoke the callback.
TrackRenderer[] renderers = new TrackRenderer[ClassExoPlayer.RENDERER_COUNT];
renderers[ClassExoPlayer.TYPE_VIDEO] = videoRenderer;
renderers[ClassExoPlayer.TYPE_AUDIO] = audioRenderer;
renderers[ClassExoPlayer.TYPE_TEXT] = textRenderer;
player.onRenderers(renderers, bandwidthMeter);

,,,

dheeraj9198 commented 8 years ago

AlirezaGhanbarinia

Include file decryption code in http server. Playing encrypted mp4 file is not a good choice because whole file has to be decrypted. Try protocols like hls and mpeg-dash as in these protocols small files need to be decrypted which is fast.

If don't want to use http server use file data source.

AlirezaGhanbarinia commented 8 years ago

@dheeraj9198

Thanks for your response,

Currently we support HLSE for streaming but we need to download some videos on Android device and this should be secure. This is why we need to encrypt and decrypt whole file. Users should be able to play the video in offline mode,

Any thoughts?

dheeraj9198 commented 8 years ago

hls video can be played in offline mode too. download all chinks and override filedatasource to decrypt chunks.