Giter VIP home page Giter VIP logo

encryptedexoplayerdemo's People

Contributors

moagrius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

encryptedexoplayerdemo's Issues

Encrypted Video Playback Error with Exoplayer - AES/CTR/NoPadding

in my project i am using .mov video format. and i simply download the video in encrypted and save the dummy name test.mov but when we are decrypt the video and play through exoplayer it gives the error which is mention below

E/ExoPlayerImplInternal: Playback error.

com.google.android.exoplayer2.ExoPlaybackException
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.throwDecoderInitError(MediaCodecRenderer.java:441)

    at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodec(MediaCodecRenderer.java:428)

    at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:920)

    at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:503)

    at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:557)

    at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)

    at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:158)
    at android.os.HandlerThread.run(HandlerThread.java:61)


 Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.qcom.video.decoder.avc, Format(1, null, video/avc, -1, null, [1280, 720, -1.0], [-1, -1])

Try Your code

I tried the source code you created. but i get an error

java.lang.IllegalArgumentException: You need to supply a url to a clear MP4 file to download and encrypt, or modify the code to use a local encrypted mp4
03-02 11:20:17.503 1738-1738/com.test.exoplayer2 W/System.err: at com.test.exoplayer2.DownloadAndEncryptFileTask.(DownloadAndEncryptFileTask.java:28)
03-02 11:20:17.503 1738-1738/com.test.exoplayer2 W/System.err: at com.test.exoplayer2.MainActivity.encryptVideo(MainActivity.java:94)
03-02 11:20:17.503 1738-1738/com.test.exoplayer2 W/System.err: at java.lang.reflect.Method.invoke(Native Method)
03-02 11:20:17.503 1738-1738/com.test.exoplayer2 W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)

Because my in MainActivity.java line 94
new DownloadAndEncryptFileTask(null, mEncryptedFile, encryptionCipher).execute();
in class DownloadAndEncryptFileTask constructor
public DownloadAndEncryptFileTask(String url, File file, Cipher cipher) { if (url == null || url.isEmpty()) { throw new IllegalArgumentException("You need to supply a url to a clear MP4 file to download and encrypt, or modify the code to use a local encrypted mp4"); } mUrl = url; mFile = file; mCipher = cipher; }
Do I have to fill with url strings?
mohon sertakan panduan penggunaan source code. Supaya orang bisa menggunakan dan mengerti kode kamu. Sehingga dia bisa berkembang dengan cepat.
Maaf ini hanya saran saya

Online EncryptedExoplayerDemo

After a long time not working on streaming file encryption I finally had an idea and tried to implement it. I tried to find more information about exoplayer and I found the okhttpdatasource library, I think the concept of okhttpdatasource is almost similar to EncryptedFileDataSource that you have created, some equations using inputstream. I tried combining okhttpdatasource with EncryptedFileDataSource, finally successfully playing. But when I ran the audio, I can't move it. I tried to detect errors and try to get a difference. The mInputStream variable in the EncryptedFileDataSource classs I try to get the number of bytes every time the read function reads the result the byte changes but when I mInputStreamdi classs OnlineEncryptedFileDataSource byte it remains 0.
I really don't know what to do for that, and until now I don't have a new idea to solve this problem maybe because I don't know how to work the search bar in exoplayer.
Please help from Mr. Moagrius. A little information might make me have an idea to solve my problem.
Thank you for your attention and assistance.
this sample code https://github.com/rohanisuhadi/DemoStreamingEncryptionExoplayer/blob/master/app/src/main/java/com/example/suhadi/demostreamingencryptionexoplayer/OnlineEncryptedFileDataSource.java

When play second times give error.

first time download the video file and play perfectly but when I close the app and hit download button it correctly says file already found no need to download again and when I hit play it gives me following error:
2018-12-23 20:05:36.879 24151-25913/com.test.exoplayer2 E/ExoPlayerImplInternal: Source error. com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor) could read the stream. at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:705) at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:628) at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:295) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:762)

how to solve problem of EncryptedExoPlayerDemo with more than 2GB files ?

Hi
Recently I used EncryptedExoPlayerDemo to play encrypted files it has no problem in playing files with less than 2GB volume but unfortunately, I couldn't play more to 2GB files.
Is there any solution for solving this problem.
Thanks so much.

error :

Source error.
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor) could read the stream.

com.google.android.exoplayer2.source.UnrecognizedInputFormatException

When I tried to play an encrypted file using the same codes of your facing this issue.

ExoPlayerImplInternal: Source error. com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor) could read the stream. at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:973) at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:891) at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764)

Playing excrypted URL on the fly

Hi @moagrius
Is there any possibility to play encrypted video URL on the fly? Encryption follows is AES/CTR/NoPadding
The method mentioned by you in this repo is working fine with local encrypted video if I put the same video from URL to local storage.
The code that I have tried is below, the rest of the code is a copy of DefaultHTTPDataSource in exoplayer package
SecretKeySpec sks = new SecretKeySpec(key, "AES"); Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, sks, ivParameterSpec); InputStream inputStream = connection.getInputStream(); this.inputStream = new StreamingCipherInputStream(inputStream, cipher);

Video gives error after few minutes

2018-12-30 16:18:24.750 15013-2510/com.aylive.ayboxoffice E/ExoPlayerImplInternal: Source error. java.io.EOFException at com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFromDataSource(DefaultExtractorInput.java:252) at com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFully(DefaultExtractorInput.java:67) at com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFully(DefaultExtractorInput.java:76) at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:431) at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:153) at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:635) at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:295) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)

don't know why this is happening.

Not able to play encrypted video file..

i am trying to play own encrypted video with specific key..and used same key in your code ..but still facing below error in response..

com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor) could read the stream.

apk

Is there a .apk example available?

How to decrypt and save file locally?

Hi, I am using this for encrypting and saving that file locally, afterwards i'm simply playing my encrypted videos from playVideo() method.. and it's working really fine.
But now i want to decrypt and save this video locally how can i achieve that ? Please suggest

de

can it use the same way on decrypted ? i have tried it,but i fail.

Can't play offline video

Hi, i tweaked code which is now open video from sdcard and encrypt it and it works perfect for the first time, but for second time when i close and reopen application it gives me following

com.example.myapplication E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor) could read the stream.
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:722)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:645)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:295)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

can you please suggest me something below is my code for EncryptFileTask

public class EncryptFileTask extends AsyncTask<Void, Void, Boolean> {

    private File inputFile;
    private File mFile;
    private Cipher mCipher;

    public EncryptFileTask(File inputFile, File file, Cipher cipher) {

        this.inputFile = inputFile;
        mFile = file;
        mCipher = cipher;
    }

    private boolean downloadAndEncrypt() throws Exception {
        try {
            long startTime = System.currentTimeMillis();
            FileInputStream inputStream = new FileInputStream(inputFile);
            FileOutputStream fileOutputStream = new FileOutputStream(mFile);
            CipherOutputStream cipherOutputStream = new CipherOutputStream(fileOutputStream,
                    mCipher);

            byte buffer[] = new byte[1024 * 1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                cipherOutputStream.write(buffer, 0, bytesRead);
            }

            inputStream.close();
            cipherOutputStream.close();

            float totalTimeInSeconds = (System.currentTimeMillis() - startTime) / 1000f;
            Log.e("Encryption", "Completed for " + inputFile.getName() + " in " + totalTimeInSeconds
                    + " seconds");
            return true;
        } catch (Exception err) {
            err.printStackTrace();
            return false;
        }

//    connection.disconnect();
    }

    @Override
    protected Boolean doInBackground(Void... params) {
        try {
            return downloadAndEncrypt();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    protected void onPostExecute(Boolean aVoid) {
        Log.e(getClass().getCanonicalName(), "Encryption done");
        if (aVoid) {
            inputFile.delete();
        }
    }
}

and following is my method which play video

public void playVideo(View view) {
        mEncryptedFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/enc_oliver.mp4");
        if (hasFile()) {
            DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
            TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(
                    bandwidthMeter);
            TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
            SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
            mSimpleExoPlayerView.setPlayer(player);
            DataSource.Factory dataSourceFactory = new EncryptedFileDataSourceFactory(mCipher,
                    mSecretKeySpec, mIvParameterSpec, bandwidthMeter);
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
            try {
                Uri uri = Uri.fromFile(mEncryptedFile);
                MediaSource videoSource = new ExtractorMediaSource(uri, dataSourceFactory,
                        extractorsFactory, null, null);
                player.prepare(videoSource);
                player.setPlayWhenReady(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            Log.e("ERROR!!", "File not found");
        }
    }

THANK YOU!

Just wanted to say thanks for sharing your solution! Got stuck just like you with the regular CipherInputStream (that worked like a charm with an HTTP server in the middle, but not with Exo directly), and solving this would have taken me ages if I hadn't stumbled over your contribution ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.