您好,我需要显示SD卡中的视频。我将我的视频保存在SD卡中并尝试使用以下代码。但视频没有显示....请帮助我出错的地方......
我的代码:
package com.videoapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class NewvideoappActivity extends Activity
{
private VideoView vView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vView = (VideoView)findViewById(R.id.myvideoview);
vView.requestFocus();
vView.setVideoPath("/sdcard/watch.3gp");
vView.setMediaController(new MediaController(this));
vView.start();
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
logcat的:
提前致谢...
答案 0 :(得分:0)
vv = (VideoView) findViewById(R.id.videoView1);
vv.setVideoURI(Uri.parse("/sdcard/myvideo.3gp"));
vv.start();
https://github.com/commonsguy/cw-advandroid/tree/master/Media/Video 看这个例子