安卓:无法使用意图的私人路径子目录播放视频 [英] Android: Unable to play video from private path subdirectory using intent
问题描述
我能够发挥私人路径视频/data/data/com.exmaple.ui/files/final.mp4这条路。
I am able to play video from private path /data/data/com.exmaple.ui/files/final.mp4 this path.
但无法从播放的子目录像/data/data/com.exmaple.ui/files/myVideos/final.mp4,
But unable to play from subdirectory like /data/data/com.exmaple.ui/files/myVideos/final.mp4,
Intent intent = new Intent(Intent.ACTION_VIEW);
File playFile = new File("/data/data/com.exmaple.ui/files/myVideos/final.mp4");
intent.setDataAndType(Uri.fromFile(playFile), "video/mp4");
startActivity(intent);
文件创建code:
String path = getFilesDir().getAbsolutePath();
File dest = new File(path,"myVideos");
boolean mkdirs = dest.mkdirs();
File destFinal = new File(dest,"final.mp4");
destFinal.setReadable(true, false);
copyFileUsingFileStreams(inputfile,destFinal);
复制code:
private void copyFileUsingFileStreams(File source, File dest) throws IOException {
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(source);
output = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
dest.setReadable(true);
} finally {
input.close();
output.close();
}
都取得文件的可读性,它不是让我读文件像上面使用意图的原因是什么?
Have made file readable,its not allowing me to read the file like above using intents any reason?
错误:
设备1:
07-09 14:22:12.098: W/VideoView(17106): Unable to open content: file:///data/data/com.exmaple.ui/files/myVideos/final.mp4
07-09 14:22:12.098: W/VideoView(17106): java.io.IOException: setDataSource failed.
错误:设备2:
----------Private File canRead :true Exists :true
07-09 20:06:00.636: W/System.err(19371): java.io.FileNotFoundException: /sys/class/tcon/tcon/mode: open failed: ENOENT (No such file or directory)
07-09 20:06:00.636: W/System.err(19371): at libcore.io.IoBridge.open(IoBridge.java:409)
07-09 20:06:00.636: W/System.err(19371): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
07-09 20:06:00.636: W/System.err(19371): at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.hardware.SecHardwareInterface.sysfsWrite(SecHardwareInterface.java:100)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.hardware.SecHardwareInterface.setTconUIMode(SecHardwareInterface.java:343)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.app.videoplayer.activity.MoviePlayer$SecHWInterfaceWrapper.setTconUIMode(MoviePlayer.java:5980)
07-09 20:06:00.636: W/System.err(19371): at com.sec.android.app.videoplayer.activity.MoviePlayer$24.handleMessage(MoviePlayer.java:3644)
07-09 20:06:00.636: W/System.err(19371): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 20:06:00.636: W/System.err(19371): at android.os.Looper.loop(Looper.java:137)
07-09 20:06:00.636: W/System.err(19371): at android.app.ActivityThread.main(ActivityThread.java:5455)
07-09 20:06:00.636: W/System.err(19371): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 20:06:00.646: W/System.err(19371): at java.lang.reflect.Method.invoke(Method.java:525)
07-09 20:06:00.646: W/System.err(19371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
07-09 20:06:00.646: W/System.err(19371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
07-09 20:06:00.646: W/System.err(19371): at dalvik.system.NativeStart.main(Native Method)
07-09 20:06:00.646: W/System.err(19371): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
07-09 20:06:00.646: W/System.err(19371): at libcore.io.Posix.open(Native Method)
07-09 20:06:00.646: W/System.err(19371): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
07-09 20:06:00.646: W/System.err(19371): at libcore.io.IoBridge.open(IoBridge.java:393)
07-09 20:06:00.646: W/System.err(19371): ... 14 more
奇迹根subfloder如何使这里的区别?任何限制提及?
文件提供商或内容提供商选择呢?
谢谢
尼茨
Wonder how root and subfloder making a difference here? any restrictions mentioned? File provider or the Content provider are the options? Thanks Nitz
推荐答案
既然你有这样的例外:
java.io.FileNotFoundException: /sys/class/tcon/tcon/mode: open failed: ENOENT (No such file or directory)
表示存在的文件doesn't或者你没有必要了正确的文件路径。
Means that the file doesn´t exist or you don´t have the correct path to the file.
使用来代替:
File playFile = new File(Environment.getExternalStorageDirectory() + "/data/data/com.exmaple.ui/files/myVideos/final.mp4");
if(playFile.exists()){
intent.setDataAndType(Uri.fromFile(playFile), "video/mp4");
startActivity(intent);
}else{
Toast.makeText(getApplicationContext(), "The file doesn´t exist!", Toast.LENGTH_LONG).show();
}
或
File playFile = new File(Environment.getExternalStorageDirectory() + "/data/data/com.exmaple.ui/files/myVideos", "final.mp4");
if(playFile.exists()){
intent.setDataAndType(Uri.fromFile(playFile), "video/mp4");
startActivity(intent);
}else{
Toast.makeText(getApplicationContext(), "The file doesn´t exist!", Toast.LENGTH_LONG).show();
}
和非常重要的记得的添加的权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
这篇关于安卓:无法使用意图的私人路径子目录播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!