playing videoview in tab controls not working and cause force close

261 views Asked by At

Everything works fine, but in the third tab I have a videoview. It plays the video until I click on the screen to use the mediacontroller and then the app states, "Unfortunatetly 'APP NAME' has stopped" I have searched for nearly two weeks, but don't understand why the video plays, but stops the app(forces closes) when trying to use the mediacontroller..? I have tried this on a different mobile and it works and have tried setting up the tabs indiviually, but I get the same result. I have highlighted the third tab below using //PROBLEM USING MEDIACONTROLLER. I can post you the XML if you like, but this appears ok as the video does play... Please, please help.

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();
}
}
};      
}
0

There are 0 answers