从Javascript调用自定义活动来播放视频(java.lang.RuntimeException:无法暂停活动)

时间:2013-01-23 21:09:41

标签: javascript android nullpointerexception android-mediaplayer

我需要在没有控件出现的情况下全屏播放视频。我创建了一个自定义活动来执行此操作。它正在工作,但有些东西已经改变了,现在当我试图完成它时崩溃了。

Javascript电话:

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

Javascript回调代码:

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

自定义活动:

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

}

我得到的错误是:

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

我在这里缺少什么。这似乎是一个非常简单的活动但是每次都失败了super.onPause。此外,如果我删除OnCompletionListener()中的完成并使用后退按钮,我会得到相同的错误。

由于

0 个答案:

没有答案