0

I'm trying to use JCodec to get all the frames from an MP4 on my emulator. I have the following permissions in my manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

The file through my adb shell looks like this:

root@generic_x86_64:/sdcard/Download # pwd
/sdcard/Download
root@generic_x86_64:/sdcard/Download # ls -la
-rwxrwx--x root     sdcard_rw 19967250 2015-10-12 16:39 Hummingbird.MP4

I've tried doing a chmod 777 Hummingbird.MP4, but that doesn't change the last set of permissions for some reason?

The following code produces the exception below.

String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fn = baseDir + "/Download/Hummingbird.MP4";
// test dir to make sure I'm in right place
String dir = baseDir + "/Download";
File fDir = new File(dir);
Log.i("TAG", "fDir.isDir()=" + fDir.isDirectory()); // this is true
fileMp4 = new File(fn);
try {
   ch = NIOUtils.readableFileChannel(fileMp4); // line 220 in trace below
} catch (FileNotFoundException e) {
   e.printStackTrace();
}

I also did a fileMp4.exists() which returns true.

Exception

10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err: java.io.FileNotFoundException: /storage/1F1A-300C/Download/Hummingbird.MP4: open failed: EACCES (Permission denied)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:76)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at org.jcodec.common.NIOUtils.readableFileChannel(NIOUtils.java:336)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at medloh.com.mp4frames.MainActivity.onActivityResult(MainActivity.java:220)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.app.Activity.dispatchActivityResult(Activity.java:6428)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.app.ActivityThread.-wrap16(ActivityThread.java)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.os.Looper.loop(Looper.java:148)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at libcore.io.Posix.open(Native Method)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:438)
10-14 23:32:27.090 4595-4595/medloh.com.mp4frames W/System.err:     ... 14 more

See any problems with this code/configuration?

medloh
  • 941
  • 12
  • 33

1 Answers1

0

I was able to get the 'NIOUtils.readableFileChannel(fileMp4)' statment working by creating the file at /data/tmp/Hummingbird.MP4 (adb push). Not sure if it's something about /sdcard and its symbolic links, or maybe I just needed to make sure all the directories and file were owned by system instead of root.

Anyway, I'm now on to other issues and problems decoding the MP4 but that's another story.

medloh
  • 941
  • 12
  • 33