简体   繁体   English

在Android中通过OTG线连接USB播放视频?

[英]Play Video using connected USB via OTG cable in Android?

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. 我想问一下,有哪些应用程序可以通过OTG有线设备将USB连接到Android并播放其中包含的媒体(特别是视频)。

i have made a Broadcast Receiver to detect the attached USB, i want to read the content also. 我已经制作了一个广播接收器来检测附加的USB,我也想阅读内容。 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? 有人对此有所了解吗?

After researches of many days i have found the solution 经过多天的研究,我找到了解决方案

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

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. 我的建议:不是在一个临时路径中保存完整视频,而是在多个子视频中划分该视频,然后相应地替换AVPlayer的AVPlayerItem属性。

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. 您还可以将AVAssetReader返回的CMSampleBuffer转换为CGImage,然后转换为UIImage,并在UIImageView中显示,以便在从原始视频文件中拉出帧时渲染帧。

There is example code inside the AVFoundation Programming Guide that shows how to do this conversion. “AVFoundation编程指南”中有示例代码,说明如何进行此转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM