Android开发,使用ViewVideo无法播放mp4文件?
大家讲道理
大家讲道理 2017-04-17 13:39:03
[Android讨论组]

新手学习Android开发,参考书为《第一行代码》,关于视频播放那一段一直调试不过去。播放视频一直有个错误,在google里翻了好久,都没有解决,还请各位给点指导。
主要错误提示如下:
MediaPlayer﹕ Couldn't open file on client side, trying server side

代码如下


public class MainActivity extends Activity implements View.OnClickListener{ private VideoView videoView; private Button play; private Button pause; private Button replay; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); play=(Button)findViewById(R.id.play); pause=(Button)findViewById(R.id.pause); replay=(Button)findViewById(R.id.replay); videoView=(VideoView)findViewById(R.id.video_view); play.setOnClickListener(this); pause.setOnClickListener(this); replay.setOnClickListener(this); initVideoPath(); } private void initVideoPath(){ File file=new File(Environment.getExternalStorageDirectory(),"record.mp4"); videoView.setVideoPath(file.getPath()); } @Override public void onClick(View v){ switch (v.getId()){ case R.id.play: if (!videoView.isPlaying()){ videoView.start(); } break; case R.id.pause: if (videoView.isPlaying()){ videoView.pause(); } break; case R.id.replay: if (videoView.isPlaying()){ videoView.resume(); } break; } } @Override protected void onDestroy(){ super.onDestroy(); if (videoView!=null){ videoView.suspend(); } } }
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
高洛峰

initVideoPath()里面路径获取,"record.mp4"前面要加斜杠,不然找不到你写的这个路径,前面是一个文件夹,斜杠后加文件名才能找到你的文件呀。

大家讲道理

我看了一下,你的问题很可能是sd卡的路径没找对。

你解决的话,我们可以一起讨论一下。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号