如何在android中为不同的设备播放外部SD卡的视频? [英] how to play video from external sd card in android for diffrent devices?

查看:117
本文介绍了如何在android中为不同的设备播放外部SD卡的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2GB的存储卡.mp4格式的视频,我想在Android应用程序中从存储卡播放视频。

我尝试了一些代码......但是它只使用micro-max A2900设备..





Intent intent = new Intent(Intent.ACTION_VIEW);

文件sdCard = Environment.getExternalStorageDirectory();

文件文件=新文件(sdCard,/ readvideo / faithclassvideo1 .mp4);

intent.setDataAndType(Uri.fromFile(file),video / *);

startActivity(intent);

I have 2gb of videos in memory card .mp4 format , i want to play video from memory card in android App.
I have trying some code.. but its working on only micro-max A2900 Device..


Intent intent = new Intent(Intent.ACTION_VIEW);
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "/readvideo/faithclassvideo1.mp4");
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);

推荐答案

试试这个:

Try this:
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName =  "/readvideo/faithclassvideo1.mp4";
File f = new File(baseDir + File.separator + fileName);





别忘了:



Don't forget:

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





祝你好运!



Good luck!


这篇关于如何在android中为不同的设备播放外部SD卡的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆