如何从连接的USB设备播放视频

时间:2018-03-04 15:48:25

标签: android usb usb-drive

我想获取USB设备文件夹的路径。我从以下代码获取pendrive的信息

 private void showDevices() {
        HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
        while(deviceIterator.hasNext()){
            UsbDevice device = deviceIterator.next();
            mUsbManager.requestPermission(device, mPermissionIntent);
            //your code

            Log.e("usb", "name: " + device.getDeviceName() + ", " +
                    "ID: " + device.getDeviceId());
            mInfo.append(device.getDeviceName() + "\n");
            mInfo.append(device.getDeviceId() + "\n");
            mInfo.append(device.getDeviceProtocol() + "\n");
            mInfo.append(device.getProductId() + "\n");
            mInfo.append(device.getVendorId() + "\n");
            path = device.getDeviceName();
        }
    }

但是当我想从USB存储器获取文件时,我收到此错误文件未找到异常打开失败的eacces

if(new CheckForSDCard()。isSDCardPresent()){

        apkStorage = new File(device.getDeviceName()
                + "/"
                        + Utils.downloadDirectory);
    } else if (!apkStorage.exists()) {
        apkStorage.mkdir();

    }
    outputFile = new File(apkStorage, "demo.mp4");
    try {
        byte[] b = new byte[(int) outputFile.length()];
        FileInputStream fileInputStream = new FileInputStream(outputFile);
        fileInputStream.read(b);
        byte[] yourKey = Encryption.generateKey("password");
        byte[] decodedData = Encryption.decodeFile(yourKey, b);
        File outputDir = context.getCacheDir();

        outputFile = File.createTempFile("videoFile", ".mp4", outputDir);
        FileOutputStream fos = new FileOutputStream(outputFile);
        fos.write(decodedData);
        fos.flush();

    } catch (Exception e) {

        //Read exception if something went wrong
        e.printStackTrace();
        Writer writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        String s = writer.toString();
        Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
        outputFile = null;

    }`

0 个答案:

没有答案
相关问题