0

次のコードを使用して、Phonegap/CordovaプラグインからYouTubeStandalonePlayerインテントを開始します。

package com.remcob00.plugins.youtube;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubeStandalonePlayer;

public class YouTube extends Plugin {

@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
    try {
        JSONObject jo = args.getJSONObject(0);
        doSendIntent(jo.getString("videoid")); 
        return new PluginResult(PluginResult.Status.OK);
    } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

private void doSendIntent(String videoid) {
    // API key instructions https://developers.google.com/youtube/android/player/register
    Intent youtubeIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) this.cordova, "YOUR_API_KEY", videoid);
    this.cordova.startActivityForResult(this, youtubeIntent, 0);
}

}

GitHubのプラグイン

ただし、問題は、YouTubeインテントを開いて、戻るボタンIを押すと、インテントを開いたページではなく、index.htmlファイルに戻ることです。どうすればこれを修正できますか?

4

2 に答える 2

0

より良い解決策が見つからない場合は、ページが変更されるたびに window.localStorage を使用して現在の場所を保存し、index.html が開かれたときに Resume イベントを検出し、window.localStorage の値が空でないかどうかを確認します。 .

そうでない場合は、単にその場所にリダイレクトします。

于 2013-01-09T00:32:45.893 に答える