android - 如何在VideoView中播放视频?

标签 android playback android-videoview

我想在 VideoView 中播放视频。 当我尝试这样做时,出现以下错误:

这是我的源代码:

package com.video.listitem;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlayVideo extends Activity {

     VideoView mVideoView;
     MediaController mc;
     String videourl;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.videoplay);

        try {
             mVideoView = (VideoView) findViewById(R.id.videoview);
             String videourl = "rtsp://v7.cache4.c.youtube.com/CiILENy73wIaGQl25yDUbxNXTRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
             mc = new MediaController(this);
             mVideoView.setMediaController(mc);
             mVideoView.requestFocus();
             mVideoView.setVideoURI(Uri.parse(videourl));
             mc.show();
             mVideoView.start();
         } catch (Exception e) {
         //TODO: handle exception
         }  
    }
}

这是我的 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"
    android:scrollbars="none"
    android:gravity="center">

    <VideoView
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/videoview" />

</LinearLayout>

最佳答案

尝试在设备中运行应用程序,视频可能无法在模拟器中运行...

关于android - 如何在VideoView中播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7710581/

相关文章:

android - EditText 不可编辑

android - 如何在 Android MusicKit 上创建 Apple MediaPlayerController

android - 如何播放存储在在线文件服务器上的视频?

android - 如何为 google map api v2 设置默认位置和缩放级别?

android - Android无法杀死的进程?

java - 在 Android 中从不同 View 调用按钮

android - 如何知道哪些android设备支持视频播放?

java - 实现游戏播放的最佳方式?

ios - 使动画播放/暂停按钮像顶空应用一样

java - Vitamio VideView 崩溃