2

一切正常,但在第三个选项卡中我有一个视频视图。它播放视频,直到我单击屏幕以使用媒体控制器,然后应用程序状态,“不幸的是 'APP NAME' 已停止”我已经搜索了近两周,但不明白为什么视频播放,但停止尝试使用媒体控制器时应用程序(强制关闭)..?我在不同的手机上试过这个,它可以工作,并尝试单独设置标签,但我得到了相同的结果。我使用 //PROBLEM USING MEDIACONTROLLER 突出显示了下面的第三个选项卡。如果您愿意,我可以向您发布 XML,但这似乎可以播放视频...请帮助。

import android.net.*;
import android.widget.*;
import android.widget.TabHost.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.*;

public class FourActivity extends Activity {

VideoView vid;

private ViewFlipper vp = null;
private Button pre = null;
private Button auto = null;
private Button nxt = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView (R.layout.tabsiljang);//tabsiljang

TabHost th = (TabHost) findViewById (R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tab1");  
//Trying to add drawable to info tab...
//specs.setIndicator("Info",getResources().getDrawable(R.drawable.ic_menu_info_details));
//
specs.setContent(R.id.tab1);
//use below if not using drawable
specs.setIndicator("Info");
th.addTab(specs);

specs = th.newTabSpec("tab2");
specs.setContent(R.id.tab2);
//Trying to add drawable to info tab...
//int icon = android.R.drawable.ic_menu_directions;
//specs.setIndicator("Instructions",     
getResources().getDrawable(R.drawable.ic_menu_directions));use this for drswable
//use this if nit using drawable
specs.setIndicator("Instructions");
th.addTab(specs);
    //
vp = (ViewFlipper) findViewById(R.id.flipper);
pre = (Button) findViewById(R.id.pre);
pre.setOnClickListener(btnClickListener);
auto = (Button) findViewById(R.id.auto);
auto.setOnClickListener(btnClickListener);
nxt = (Button) findViewById(R.id.nxt);
nxt.setOnClickListener(btnClickListener);

//PROBLEM USING MEDIACONTROLLER             
specs = th.newTabSpec("tab3");
specs.setContent(R.id.tab3);
//Trying to add drawable to info tab...
//int icon = android.R.drawable.ic_menu_directions;
//specs.setIndicator("Video", getResources().getDrawable(R.drawable.video_icon));
//use this if using drawable

specs.setIndicator("Video"); //use this if not using draeable
th.addTab(specs);

vid = (VideoView)findViewById(R.id.video);
String urlpath = "android.resource://" + getPackageName() + "/" + R.raw.video2;
vid.setVideoURI(Uri.parse(urlpath));
vid.start();
MediaController mc = new MediaController(this);
mc.setMediaPlayer(vid);
vid.setMediaController(mc);

}

private OnClickListener btnClickListener = new View.OnClickListener() {

@Override
public void onClick(View v) {
if(pre.getId() == v.getId()){
vp.showPrevious();
}else if(auto.getId() == v.getId()){
vp.startFlipping();
}else if(nxt.getId() == v.getId()){
vp.showNext();
}
}
};      
}
4

0 回答 0