Play video using connected USB via OTG cable in Android?

I want to ask if there is an application in which a user can connect USB to Android via an OTG cable device and play the media contained therein (especially video).

I made a broadcast receiver to detect a connected USB, I also want to read it. I am using this piece of code.

private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { synchronized (this) { UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if(device != null){ // Log.d("1","DEATTCHED-" + device); } } } // if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) { synchronized (this) { UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if(device != null){ // Log.d("1","ATTACHED-" + device); } } else { PendingIntent mPermissionIntent; mPermissionIntent = PendingIntent.getBroadcast(MainActivity.this, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_ONE_SHOT); mUsbManager.requestPermission(device, mPermissionIntent); } } } // if (ACTION_USB_PERMISSION.equals(action)) { synchronized (this) { UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if(device != null){ // Log.d("1","PERMISSION-" + device); } } } } } }; 

I want to make such an application.

Does anyone have an idea about this?

+6
source share
2 answers

After several days of research, I found a solution

https://github.com/1hakr/AnExplorer

+3
source

Splitting videos into multiple sub-videos may work for you.

What I suggest: instead of saving the full video on one time path, split this video into several sub-videos and then replace the AVPlayerItem property for AVPlayer accordingly.

So now the functionality works just like streaming a video. :)

You can also convert the CMSampleBuffer, which AVAssetReader will return to CGImage, and then UIImage and display that in UIImageView to display frames when they are output from the original video file.

There is sample code inside the AVFoundation programming guide that shows how to do this conversion.

0
source

Source: https://habr.com/ru/post/985112/


All Articles