Hi,
I was working on developing a VideoPlayer. I am getting an error while
running the .mp4 file on VideoView. This error occurs when I click on the
video view when the video is playing or if I start the video directly. The
error dialogue that appears on the screen says application stopped
unexpectedly.
Does anyone knows whats wrong with my code. Is there any other thing that I
need to do like adding permissions or intent filters.
Here is the code that can give more understanding about my application Video
Player..
public class VideoPlayer extends Activity {
VideoView videoview;
Context context;
Bundle bundle;
Intent sender;
volatile boolean FLAG_FOR_FAVORITE;
volatile boolean FLAG_FOR_PLAY_PAUSE = false;
MediaController mediaController;
TextView wordtext;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this.getApplicationContext();
sender = this.getIntent();
setContentView(R.layout.videoplayer);
Bundle retrieving_bundle = sender.getExtras();
String wordname = retrieving_bundle.getString("txtstring");
String filename = "/sdcard/" + wordname + ".mp4";
ImageButton playpause = (ImageButton)findViewById(R.id.playpause);
mediaController = new MediaController(context);
wordtext = (TextView)findViewById(R.id.vocabularyword);
wordtext.setText(wordname);
///////////////Code for setting video View //////////
try{
videoview = (VideoView)findViewById(R.id.wordvideo);
videoview.setVideoPath(filename);
videoview.setMediaController(mediaController);
videoview.requestFocus();
//videoview.start(); *This gives an error if
not commented This is what I meant by running directly*
videoview.setClickable(false);
videoview.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(FLAG_FOR_PLAY_PAUSE == false){
FLAG_FOR_PLAY_PAUSE = true;
videoview.start();
}
////to remove from favorites ///////////
else if(FLAG_FOR_PLAY_PAUSE == true){
FLAG_FOR_PLAY_PAUSE = false;
videoview.pause();
}
}
});
}
catch(Exception e){
Log.v("video",e.getMessage());
}
playpause.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
ImageButton pauseplay =
(ImageButton)findViewById(R.id.playpause);
///// to add to favorites/////////////
if(FLAG_FOR_PLAY_PAUSE == false){
pauseplay.setImageResource(R.drawable.pause);
FLAG_FOR_PLAY_PAUSE = true;
videoview.start();
}
////to remove from favorites ///////////
else if(FLAG_FOR_PLAY_PAUSE == true){
pauseplay.setImageResource(R.drawable.play);
FLAG_FOR_PLAY_PAUSE = false;
videoview.pause();
}
}
});
}
The logcat shows the following:
12-10 11:53:12.931: WARN/WindowManager(52): at
com.android.server.WindowManagerService$Session.onTransact(WindowManagerService.java:6427)
12-10 11:53:12.931: WARN/WindowManager(52): at
android.os.Binder.execTransact(Binder.java:287)
12-10 11:53:12.931: WARN/WindowManager(52): at
dalvik.system.NativeStart.run(Native Method)
12-10 11:53:12.931: WARN/WindowManager(52): Attempted to add window with
token that is not a window: null. Aborting.
12-10 11:53:12.941: DEBUG/AndroidRuntime(3035): Shutting down VM
12-10 11:53:12.941: WARN/dalvikvm(3035): threadid=3: thread exiting with
uncaught exception (group=0x4001b188)
12-10 11:53:12.951: ERROR/AndroidRuntime(3035): Uncaught handler: thread
main exiting due to uncaught exception
12-10 11:53:13.041: DEBUG/dalvikvm(3035): GC freed 2397 objects / 340176
bytes in 89ms
12-10 11:53:13.081: ERROR/AndroidRuntime(3035):
android.view.WindowManager$BadTokenException: Unable to add window -- token
null is not valid; is your activity running?
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewRoot.setView(ViewRoot.java:468)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.widget.MediaController.show(MediaController.java:304)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.widget.MediaController.show(MediaController.java:249)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.widget.VideoView.toggleMediaControlsVisiblity(VideoView.java:538)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.widget.VideoView.onTouchEvent(VideoView.java:489)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.View.dispatchTouchEvent(View.java:3709)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:820)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:820)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:820)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:820)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:820)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.app.Activity.dispatchTouchEvent(Activity.java:2061)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1690)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.os.Handler.dispatchMessage(Handler.java:99)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.os.Looper.loop(Looper.java:123)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
android.app.ActivityThread.main(ActivityThread.java:4310)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
java.lang.reflect.Method.invokeNative(Native Method)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
java.lang.reflect.Method.invoke(Method.java:521)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-10 11:53:13.081: ERROR/AndroidRuntime(3035): at
dalvik.system.NativeStart.main(Native Method)
Thanks in advance,
Yousuf
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en