Calling a custom activity from Javascript to play a video (java.lang.RuntimeException: Unable to pause activity)

I need to play a video full-screen without the controls showing up. I created a custom activity to do this. It was working but something has changed and now it crashes when I try to finish() it.

Javascript call:

jiPlayVideo.PlayVideo('/sdcard/download/V2.3gp');

Javascript callback code:

public class JavascriptInterface {

      //private WebView mAppView;
      private MainActivity mGap;

      public JavascriptInterface(MainActivity gap, WebView view)
      {
        mGap = gap;
      }

      public String PlayVideo(String myURL){
                      Intent intent = new Intent(mGap, VideoActivity.class);
                      Bundle b = new Bundle();
                      b.putString("myURL", myURL);
                      intent.putExtras(b); //Put your id to your next Intent
                      startActivity(intent);

                      return("");
      }
    }

Custom Activity:

package com.RGi.SynchedIn;

import org.apache.cordova.DroidGap;

import com.RGi.SynchedIn.MainActivity.JavascriptInterface;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.VideoView;

public class VideoActivity extends DroidGap {
public static VideoActivity theVideoActivity;

@Override
public void onCreate(Bundle savedInstanceState) {         

   super.onCreate(savedInstanceState);
   super.init();

   theVideoActivity = this;
   setContentView(R.layout.videoview);

   VideoView v = (VideoView) findViewById(R.id.video);
   Bundle b = getIntent().getExtras();
   String myFolder =  b.getString("myURL");

   v.setVideoPath(myFolder);
   v.start();
   v.setOnCompletionListener(mCompletionListener);

}

private MediaPlayer.OnCompletionListener mCompletionListener =  
         new MediaPlayer.OnCompletionListener() {  
         public void onCompletion(MediaPlayer mp) { 
            finish();
         }  
     };  

     @Override
     public void onStart() {
         super.onStart();
     }

    @Override
     public void onResume() {
         super.onResume();
     }

     @Override
     public void onPause() {
         super.onPause();
     }

     @Override
     public void onStop() {
         super.onStop();
     }

    @Override
     public void onDestroy() {
         super.onDestroy();
     }

}

The error that I am getting is:

01-23 16:01:56.584: E/AndroidRuntime(7486): FATAL EXCEPTION: main
01-23 16:01:56.584: E/AndroidRuntime(7486): java.lang.RuntimeException: Unable to pause activity {com.RGi.SynchedIn/com.RGi.SynchedIn.VideoActivity}: java.lang.NullPointerException
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2358)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2315)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2295)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread.access$1700(ActivityThread.java:117)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:946)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.os.Looper.loop(Looper.java:130)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread.main(ActivityThread.java:3687)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at java.lang.reflect.Method.invoke(Method.java:507)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at dalvik.system.NativeStart.main(Native Method)
01-23 16:01:56.584: E/AndroidRuntime(7486): Caused by: java.lang.NullPointerException
01-23 16:01:56.584: E/AndroidRuntime(7486):     at java.lang.String.indexOf(String.java:1145)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at org.apache.cordova.CordovaWebView.loadUrlNow(CordovaWebView.java:507)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at org.apache.cordova.CordovaWebView.loadUrl(CordovaWebView.java:392)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at org.apache.cordova.CordovaWebView.handlePause(CordovaWebView.java:907)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at org.apache.cordova.DroidGap.onPause(DroidGap.java:632)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at com.RGi.SynchedIn.VideoActivity.onPause(VideoActivity.java:59)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.Activity.performPause(Activity.java:3851)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191)
01-23 16:01:56.584: E/AndroidRuntime(7486):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2345)
01-23 16:01:56.584: E/AndroidRuntime(7486):     ... 12 more

What am I missing here. This seems like a very simple activity But fails the super.onPause everytime. Also, if I remove the finish in OnCompletionListener() and use the back button I get the same error.

Thanks

Answers


Need Your Help

Merging two files with awk and changing last column for duplicates

file join awk merge

I have two tab-delimited text files. I want to create an output file that has all the lines in file 1. However if the value in column 1 in file 1 matches column 1 in file 2, I would like the value in

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.