1

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

我的菜单

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>

和清单

<?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>

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

4

2 回答 2

1

我想,你只是错过了一件小事:一个点 (.)

在此处查看您的代码:

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

你不认为它应该是这样的:

Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);
于 2013-11-09T05:28:41.577 回答
0

尝试使用:

mVideoView.start();
于 2013-11-09T04:32:54.020 回答