您的位置:首页 > 移动开发 > 微信开发

用VideoView写的小程序运行时黑屏

2015-07-02 21:49 621 查看
源代码如下:
package com.example.videoviewtest;

import java.io.File;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

/**
* Description:
* <br/>site: <a href="http://www.crazyit.org">crazyit.org</a>
* <br/>Copyright (C), 2001-2014, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author  Yeeku.H.Lee kongyeeku@163.com
* @version  1.0
*/
public class VideoViewTest extends Activity
{
VideoView videoView;
MediaController mController;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
// 获取界面上VideoView组件
videoView = (VideoView) findViewById(R.id.video);
// 创建MediaController对象
mController = new MediaController(this);
File video = new File("/mnt/shell/emulated/0/Movies/a.mp4");
if(video.exists())
{
videoView.setVideoPath(video.getAbsolutePath());  //①
// 设置videoView与mController建立关联
videoView.setMediaController(mController);  //②
// 设置mController与videoView建立关联
mController.setMediaPlayer(videoView);  //③
// 让VideoView获取焦点
videoView.requestFocus();
            videoView.start();
}
}
}
这是用的Genymotion 模拟器,所以文件路径写成那样,跟Google自带的模拟器不一样。但是那个路径存在错误。应该把路径换成Environment.getExternalStoreage() + "/Movies/a.mp4"这样。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: