Intent tostart = new Intent(Intent.ACTION_VIEW);
tostart.setDataAndType(Uri.parse(video_path+".***"), "video/*");
startActivity(tostart);
假设我有一个文件路径
/mnt/sdcard/video/my_birthday_moovie001
“my_birthday_moovie001”可以是.mkv
,.mpg
或.mkv
。我尝试将“。***”添加到文件路径,但仍然无法打开文件。
好吧,我读了注释,您已将路径存储在不带扩展名的db中,存在许多扩展名,因此android无法自动选择您必须创建某种方式来检测扩展名的扩展名。
以下是一种健壮的方法,最适合您的情况,但在已知扩展名的适当情况下不建议使用
public String chk_path(String filePath)
{
//create array of extensions
String[] ext=new String[]{".mkv",".mpg"}; //You can add more as you require
//Iterate through array and check your path which extension with your path exists
String path=null;
for(int i=0;i<ext.Length;i++)
{
File file = new File(filePath+ext[i]);
if(file.exists())
{
//if it exists then combine the extension
path=filePath+ext[i];
break;
}
}
return path;
}
现在在您的代码中播放歌曲
if(chk_path(video_path)!=null)
{
Intent tostart = new Intent(Intent.ACTION_VIEW);
tostart.setDataAndType(Uri.parse(video_path), "video/*");
startActivity(tostart);
}
else
//tell user that although the path in database but file on this path do not exists
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句