5

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?

Marcus
  • 6,697
  • 11
  • 46
  • 89
hitesh141
  • 963
  • 12
  • 25
  • i found a project here : https://github.com/danny-source/List-USB-OTG – hitesh141 Apr 14 '15 at 10:49
  • @ paresh: then why you are marking it as off topic? – hitesh141 Apr 28 '15 at 12:50
  • 2
    The reason I voted to close this question is because you didn't included the code or the enough details nor even what have you tried. You can check your [question revision](http://stackoverflow.com/posts/29625384/revisions), you have asked this question on 14th but later you have included the code. I can't take my close vote reverse back, that's the limitation or a rule that once you did a close vote, you can't take it back, but yes later you can make a vote for opening the thread again! – Paresh Mayani Apr 28 '15 at 12:53
  • yes i have put the code after sometime. Please help me out if you can in this. – hitesh141 Apr 28 '15 at 12:57
  • What you mean under USB? It's storage device or what? – once2go Jul 01 '15 at 14:18

2 Answers2

2

After researches of many days i have found the solution

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

hitesh141
  • 963
  • 12
  • 25
0

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.

akhil verma
  • 390
  • 1
  • 3
  • 15
  • I want to ask the basic core question that how can i read the data which resides in attached USB device. I am unable to get that data. Once i get that data which is in video form. Then i will use your opinion. – hitesh141 Jul 03 '15 at 05:01