【问题标题】:Android Play Encrypted Video with libmedia :java.io.FileNotFoundException: No content provider:Android 播放带有 libmedia 的加密视频:java.io.FileNotFoundException:没有内容提供者:
【发布时间】:2016-11-21 21:29:44
【问题描述】:

我有可以使用 libmedia lib 播放加密视频的基本应用程序。

视频加密方法工作正常。

但播放视频时会显示此错误消息

路径为空 setDataSource IOException 发生:java.io.FileNotFoundException:没有内容提供者:http://127.0.0.1:36316/http://127.0.0.1:36316/storage/emulated/0/AB/b.mp4

这是我的加密方法

    public static void encrypt() throws Exception {
    final byte[] buf = new byte[8192];
    final Cipher c = Cipher.getInstance("AES/CTR/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec("1234567890123456".getBytes(), "AES"), new IvParameterSpec(new byte[16]));
    final InputStream is = new FileInputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/AB/"+"a.mp4");
    final OutputStream os = new CipherOutputStream(new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/AB/"+"b.mp4"), c);
    while (true) {
        int n = is.read(buf);
        if (n == -1) break;
        os.write(buf, 0, n);
    }
    os.close(); is.close();
}

这是我的播放按钮

PlayBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/AB/b.mp4");

           try {
              mServer = new LocalSingleHttpServer();
            } catch (IOException e) {
               e.printStackTrace();
           }

           String path = mServer.getURL(file.getPath());

            try {
                mServer.setCipher(myGetCipher());
                mServer.start();
                path = mServer.getURL(path);
                videoView.setVideoPath(path);
                videoView.start();
            }catch (Exception e){
             e.printStackTrace();
            }



        }
    });

GetCyper() 方法

 private Cipher myGetCipher() throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException {
    // avoid the default security provider "AndroidOpenSSL" in Android 4.3+ (http://libeasy.alwaysdata.net/network/#provider)
    Cipher c = Cipher.getInstance("ARC4", "BC");
    c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("BrianIsInTheKitchen".getBytes(), "ARC4"));
    return c;
}

编译

编译SdkVersion 23
buildToolsVersion "23.0.3"

错误信息

setDataSource IOException happend : 
                                java.io.FileNotFoundException: No content provider: http://127.0.0.1:40208/storage/emulated/0/AB/b.mp4
                                at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1053)
                                at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
                                at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
                                at android.media.MediaPlayer.setDataSource(MediaPlayer.java:979)
                                at android.widget.VideoView.openVideo(VideoView.java:338)
                                at android.widget.VideoView.setVideoURI(VideoView.java:248)
                                at android.widget.VideoView.setVideoURI(VideoView.java:238)
                                at android.widget.VideoView.setVideoPath(VideoView.java:234)
                                at encrypt.amg.com.encryptiont2.MainActivity$2$override.onClick(MainActivity.java:89)

【问题讨论】:

    标签: android video encryption


    【解决方案1】:

    你调用 getURL 两次。

    字符串路径 = mServer.getURL(file.getPath());

    path = mServer.getURL(path);

    【讨论】:

      【解决方案2】:

      sky 的回答是正确的:无论如何,修复对 getURL() 的双重调用是强制性的。

      之后,日志条目java.io.FileNotFoundException: No content provider:还是正常的。请注意,消息级别不是错误而是调试。这就是 Android 播放器组件的行为方式:无论路径内容是什么,它首先尝试将其作为本地资源,如果失败,它将回退到远程资源。您会在下一条调试消息中看到这一点:Couldn't open file on client side, trying server side。此时,库被命中。

      如果视频无法播放,则说明其他地方有问题。例如,在您的代码示例中,加密和解密 (AES/ARC4) 的密码不同。

      【讨论】:

      • 感谢您的评论。该错误已修复。这是因为我用来加密的密码密钥。这些密钥彼此不同。无论如何,我想知道什么是视频最简单的视频加密。 《ARC4》好看吗?我已经将它用于 2.8GB 的​​视频文件。但没有视频正在播放。只有视频加载图标。但是这个在小视频文件(100 MB)上可以正常播放
      【解决方案3】:

      您可能还需要在解密端设置 IVParameters,就像您在初始化 Cipher 时在加密端所做的那样。

      c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("BrianIsInTheKitchen".getBytes(), "ARC4"), new IVParameterSpec(new byte[16]));

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-25
        • 2011-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多