【android】 Unable to open content: file:///sdcard/hello.3gp 3gp视频不能播放
来源:互联网 发布:java有什么证书 编辑:程序博客网 时间:2024/05/26 15:55
【报错】
sd卡对应路径中已放置相关视频,但运行还是会报下面的错误:
VideoView: Unable to open content: file:///sdcard/hello.3gp
java.io.FileNotFoundException: /sdcard/hello.3gp: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.(FileInputStream.java:76)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1095)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1046)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:992)
at android.widget.VideoView.openVideo(VideoView.java:346)
at android.widget.VideoView.setVideoURI(VideoView.java:256)
at android.widget.VideoView.setVideoURI(VideoView.java:239)
………….很多
【先说解决方法】
少了一个访问sd卡的权限 在AndroidManifest.xml文件中加入
允许应用程序读取扩展存储器 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
访问sd卡中数据需要权限。
【更改后结果】可以正常播放
【下面分享代码】
【java】
package irdc.ex07_13;import android.app.Activity;import android.graphics.PixelFormat;import android.media.MediaPlayer;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.MediaController;import android.widget.TextView;import android.widget.Toast;import android.widget.VideoView;public class EX07_13 extends Activity{ private TextView mTextView01; private VideoView mVideoView01; private String strVideoPath = ""; private Button mButton01, mButton02; private String TAG = "HIPPO_VIDEOVIEW"; /* 预设判别sd卡存在flag為false */ private boolean bIfSDExist = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 全屏幕 */ getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.main); /* 判断sd卡是否存在 */ if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { bIfSDExist = true; } else { bIfSDExist = false; mMakeTextToast ( getResources().getText(R.string.str_err_nosd).toString(), true ); } mTextView01 = (TextView)findViewById(R.id.myTextView1); mVideoView01 = (VideoView)findViewById(R.id.myVideoView1); /* 延伸学会 */ mVideoView01.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { // TODO Auto-generated method stub mTextView01.setText(strVideoPath); } }); mVideoView01.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer arg0) { // TODO Auto-generated method stub mMakeTextToast ( getResources().getText(R.string.str_complete).toString(), true ); } }); mButton01 = (Button)findViewById(R.id.myButton1); mButton02 = (Button)findViewById(R.id.myButton2); mButton01.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(bIfSDExist) { strVideoPath = "file:///sdcard/hello.3gp"; playVideo(strVideoPath); } } }); mButton02.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(bIfSDExist) { /* 延伸学会 */ //resetVideo(); strVideoPath = "file:///sdcard/test.3gp"; playVideo(strVideoPath); } } }); } private void playVideo(String strPath) { if(strPath!="") { /* 呼叫VideoURI方法,指定解析路径 */ mVideoView01.setVideoURI(Uri.parse(strPath)); /* 设定控制Bar显示于此Context中 */ mVideoView01.setMediaController(new MediaController(EX07_13.this)); mVideoView01.requestFocus(); /* 呼叫VideoView.start()自动播放 */ mVideoView01.start(); if(mVideoView01.isPlaying()) { /* 下程式不会执行,因start()后尚需要preparing() */ mTextView01.setText("Now Playing:"+strPath); Log.i(TAG, strPath); } } } /* private void resetVideo() { if(mVideoView01!=null) { mVideoView01.seekTo(0); } } */ public void mMakeTextToast(String str, boolean isLong) { if(isLong==true) { Toast.makeText(EX07_13.this, str, Toast.LENGTH_LONG).show(); } else { Toast.makeText(EX07_13.this, str, Toast.LENGTH_SHORT).show(); } }}
【xml】 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/white"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/myTextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/blue"
android:text="@string/hello"
/>
<VideoView
android:id="@+id/myVideoView1"
android:layout_width="320px"
android:layout_height="240px"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/myButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_button1" />
<Button
android:id="@+id/myButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_button2" />
</LinearLayout>
</LinearLayout>
以上代码由george_hsieh@qq.com提供。
如有补充欢迎评论。
- 【android】 Unable to open content: file:///sdcard/hello.3gp 3gp视频不能播放
- android mp4 3gp视频播放程序
- 3GP视频转换器代码
- android使用VideoView设计的扫描全局.mp4和.3gp的视频播放器
- Android第八讲——多媒体(四)播放视频(mp4/3gp) MediaPlayer
- 如何得知3GP檔案結構? (3GP file information)
- android在线播放mp4/3gp
- android在线播放mp4/3gp
- android在线播放mp4/3gp
- .3gp 文件播放初窥
- 视频容器解析之3GP
- Java获取3gp视频时长
- 解决IOS无法播放3gp视频, 出现无法编码问题
- Android Debug.startMethodTracing() 报错 Unable to open trace file '/sdcard/*.trace': Permission denied
- 3gp文件格式研究
- 3GP文件格式分析
- 3GP概述
- 3gp的文件格式
- Oracle 11g Data Guard 之角色转换
- 安卓异常android.os.networkonmainthreadexception的解决方法
- 51+TA8435h驱动步进电机经过光耦后出现的问题
- Android Preference 须知
- 【HUSTOJ】1088: 查找“支撑数”
- 【android】 Unable to open content: file:///sdcard/hello.3gp 3gp视频不能播放
- 【HDU 3652】B-number(数位dp)
- Android系统自带样式(@android:style/)
- excle中字符串选取#好读书,读好书#--好读书,读好书
- 设计模式之桥接模式
- jqeury中ajax的表单实现异步提交
- Leetcode 28.Implement strStr() 解题报告【C库函数strstr()模拟-字符串中子串首次出现的地址】
- 关于android核心组件Activity的一些总结
- 线程进程通信和同步方式