android - Play local aes128 cbc encrypted mp3 with ExoPlayer -


i wonder best way play local aes128-cbc encrypted mp3 file exoplayer. there class aes128datasource seems exist purpose, can't exoplayer play file. returns -1 track duration indicates file somehow corrupt. there not information error since there nothing in logs. mp3 not played. guess file not decrypted correctly. can give example of how it? here do:

key , iv:

private byte[] iv = hextobytes("..."); //32 hex symbols here string private byte[] key = hextobytes("..."); //32 hex symbols here string 

hextobytes function converts given key , iv hex string byte[]:

private byte[] hextobytes(string str) {     if (str == null) {         return null;     }     else if (str.length() < 2) {         return null;     }     else {         int len = str.length() / 2;         byte[] buffer = new byte[len];         (int = 0; < len; i++) {             buffer[i] = (byte) integer.parseint(str.substring(i * 2, * 2 + 2), 16);         }         return buffer;     } } 

and here play encrypted file:

uri uri = uri.parse("android.resource://" + context.getpackagename() + file.separator + r.raw.track01_cbc); defaultbandwidthmeter bandwidthmeter = new defaultbandwidthmeter(); string useragent = getuseragent(context, ...); datasource datasource = new defaulturidatasource(context, bandwidthmeter, useragent); aes128datasource aes128datasource = new aes128datasource(datasource, key, iv); samplesource samplesource = new extractorsamplesource(uri, aes128datasource, new mp3extractor(), renderer_count, 5000); mediacodecaudiotrackrenderer audiorenderer = new mediacodecaudiotrackrenderer(samplesource); exoplayer.prepare(audiorenderer); exoplayer.setplaywhenready(true); 

according developer of exoplayer aes128datasource meant part of using hls streaming. in next versions of exoplayer aes128datasource private hls package. see full answer on github. have create own datasource , implement decryption yourself.

"if can make datasource return correctly decrypted data @ offsets requested, exoplayer "just work""


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -