我有应该播放视频的项目。当我按下按钮时我的MyVideo活动没有启动,但是当我评论或删除几个方法我的活动开始时。我应该添加任何其他方法来显示活动,或者我应该添加显而易见的东西。
package com.nazad.org;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MyVideo extends Activity {
String SrcPath = "rtsp://v2.cache1.c.youtube.com/CjYLENy73wIaLQmhulgrtR-1JxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYMOcgLDU6ZWTUAw=/0/0/0/video.3gp";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView myVideoView = (VideoView) findViewById(R.id.myvideoview);
myVideoView.setScrollContainer(true) ;
myVideoView.getAnimation().setDetachWallpaper(true);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
}
这是我的开始活动,有两个按钮:
package com.nazad.org;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyNapredNazadActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button next;
Button back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
next = (Button) findViewById(R.id.next);
back = (Button) findViewById(R.id.back);
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MyNapredNazadActivity.this, MyVideo.class);
i.setClass(MyNapredNazadActivity.this, MyVideo.class);
MyNapredNazadActivity.this.startActivity(i);
}
});
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent ii = new Intent(MyNapredNazadActivity.this,
MySimple.class);
// i.setClass(MyNapredNazadActivity.this, MyVideo.class);
MyNapredNazadActivity.this.startActivity(ii);
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MyNapredNazadActivity.this, MyVideo.class);
this.startActivity(i);
}
}
和清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nazad.org"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MyNapredNazadActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MyVideo"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MySimple"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>