java - android: 无法播放视频

标签 java android xml video

我正在尝试在我的 Android 应用程序上播放视频,但是当我通过菜单列表单击该 Activity 时,该应用程序保留在列表中并且不播放视频。 代码如下

我的菜单

package com.example.taekwondobuddy.util;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Kicks extends ListActivity {

String classes[] = {"FrontKick","RoundhouseKick","AxeKick"} ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Kicks.this,   android.R.layout.simple_list_item_1, classes));
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String cheese = classes[position];
    try{
    Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
    Intent ourIntent = new Intent(Kicks.this, ourclass);
    startActivity(ourIntent);
    } catch(ClassNotFoundException e){
        e.printStackTrace();

    }
    }

 }

我要播放的视频

package com.example.taekwondobuddy.util;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

 public class RoundhouseKick extends Activity {
 private VideoView mVideoView;

 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
 setContentView(R.layout.roundhousekick);
 mVideoView = (VideoView) findViewById(R.id.roundhousekick);
 mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.roundhousekick));
 mVideoView.setMediaController(new MediaController(this));
 mVideoView.requestFocus();
 }

xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

 <VideoView
    android:id="@+id/roundhousekick"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

和 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taekwondobuddy.util"
 android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />

  <application
  android:allowBackup="true"
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name"
   android:theme="@style/AppTheme" >
   <activity
    android:name="com.example.taekwondobuddy.util.Menu"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name="com.example.taekwondobuddy.util.Tools"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>
<activity
    android:name="com.example.taekwondobuddy.util.Techniques"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>
<activity
    android:name="com.example.taekwondobuddy.util.Kicks"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >

</activity>
<activity
    android:name="com.example.taekwondobuddy.util.Counter"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >


</activity>
<activity
    android:name="com.example.taekwondobuddy.util.Time"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >


</activity>
 <activity
    android:name="com.example.taekwondobuddy.util.Accelermeter"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >


</activity>
 <activity
    android:name="com.example.taekwondobuddy.util.FrontKick"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >


</activity>
 <activity
    android:name="com.example.taekwondobuddy.util.RoundhouseKick"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >


</activity>
 <activity
    android:name="com.example.taekwondobuddy.util.AxeKick"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >


</activity>

</application> 

</manifest>

我认为 list 有问题,但我真的看不出有什么问题,有什么想法吗?另外,视频是 mp4 格式,因此它们的格式适合 android

最佳答案

我想,您只是漏掉了一件小事:一个点 (.)

在此处查看您的代码:

Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);

你不觉得应该是这样吗:

Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);

关于java - android: 无法播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19872265/

相关文章:

java - Spring 3.2 和 Jersey 2.4 的 Autowiring 问题

php - 使用 php 和 jquery 将 xml 数据上传回服务器

java - 服务生成器没有添加一些依赖项?

java - Spring 启动: Set hibernate sequence globally

java - 如何从文件(.yml)中读取字符串结果,从而通读多个文件?

java - 当您关闭并再次打开应用程序时,如何使用RadioButton进行黑暗模式操作以及如何保持主题状态

android - 如何阻止 TextView 在 LinearLayout 中拉伸(stretch)

android - 插件和应用程序发布的 Flutter 问题

xml - 根据 XSL 中的条件动态输出元素?

用于 JSON 或 XML 或其他的 Java 内置数据解析器