Play Video using connected USB via OTG cable in Android?

萝らか妹 提交于 2020-01-12 06:01:33

问题


I want to ask that there are application available in which user can connect USB to Android via OTG cable device and play the media (specially videos) contained by it.

i have made a Broadcast Receiver to detect the attached USB, i want to read the content also. I am using this code snippet.

                    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 kind of application.

Do anyone have some idea about that?


回答1:


After researches of many days i have found the solution

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




回答2:


Dividing the video in multiple sub videos may work for you.

What I suggest : instead of saving full video in one temp path, divide that video in multiple sub videos and then replaced AVPlayerItem property of AVPlayer accordingly.

So now functionality is working same as video streaming . :)

You can also convert the CMSampleBuffer that the AVAssetReader returns into a CGImage and then a UIImage and display that in a UIImageView, to render the frames as they are pulled out of the original video file.

There is example code inside the AVFoundation Programming Guide that shows how to do this conversion.



来源:https://stackoverflow.com/questions/29625384/play-video-using-connected-usb-via-otg-cable-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!