i am trying to play a youtube video in android through NanoHTTPD android web server library using a html form by providing the youtube id of some video in the served html file into the html form. So far i got the youtube video player working. And i also get the form post parameter from the html. But i having trouble combining the two.
AndroidWebServer.class
package com.martin.androidwebplayer;
import android.app.Activity;
import android.content.Context;
import fi.iki.elonen.NanoHTTPD;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class AndroidWebServer extends NanoHTTPD {
private static final String TAG = "HTTPServer";
private Context ctx;
public AndroidWebServer(int port, Context ctx) {
super(port);
this.ctx = ctx;
try {
Log.d("TAG", "Starting web server..");
start();
}
catch(IOException ioe) {
Log.e(TAG, "Unable to start the server");
ioe.printStackTrace();
}
}
#Override
public Response serve(IHTTPSession session) {
Map<String, String> parms = session.getParms();
String content = null;
content = readFile().toString();
if (session.getMethod() == Method.POST) {
Map<String, String> files = new HashMap<String, String>();
try {
session.parseBody(files);
} catch (IOException e) {
e.printStackTrace();
} catch (ResponseException e) {
e.printStackTrace();
}
**youtube(String.valueOf(session.getParms().get("fname")));**
return newFixedLengthResponse(String.valueOf(session.getParms().get("fname")));
}
return newFixedLengthResponse(content );
}
private StringBuffer readFile() {
BufferedReader reader = null;
StringBuffer buffer = new StringBuffer();
try {
reader = new BufferedReader(
new InputStreamReader
(ctx.getAssets().open("index.html"), "UTF-8"));
String mLine;
while ((mLine = reader.readLine()) != null) {
buffer.append(mLine);
buffer.append("\n");
}
}
catch(IOException ioe) {
ioe.printStackTrace();
}
finally {
if (reader != null)
try {
reader.close();
}
catch (IOException ioe) {}
}
return buffer;
}
public void stopServer() {
this.stop();
}
public void youtube(String link) {
// Get reference to the view of Video player
YouTubePlayerView ytPlayer = (YouTubePlayerView) ((Activity)ctx).findViewById(R.id.ytPlayer);
String api_key = "apikey";
ytPlayer.initialize(
api_key,
new YouTubePlayer.OnInitializedListener() {
// Implement two methods by clicking on red
// error bulb inside onInitializationSuccess
// method add the video link or the playlist
// link that you want to play In here we
// also handle the play and pause
// functionality
#Override
public void onInitializationSuccess(
YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo(link);
youTubePlayer.play();
}
// Inside onInitializationFailure
// implement the failure functionality
// Here we will show toast
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult
youTubeInitializationResult) {
}
});
}
}
MainActivity.class
package com.martin.androidwebplayer;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayerView;
import java.io.IOException;
public class MainActivity extends YouTubeBaseActivity {
private AndroidWebServer aws;
private YouTubePlayerView ytPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
YouTubePlayerView ytPlayer = (YouTubePlayerView) findViewById(R.id.ytPlayer);
aws = new AndroidWebServer(8180, MainActivity.this);
}
}
assets/index.html
<html>
<head>
<title>CSS Contact Form</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function formSubmit(){
var fname = document.getElementById("fname").value;
var dataString = 'fname='+ fname;
jQuery.ajax({
url: "http://192.168.100.42:8180",
data: dataString,
type: "POST",
success:function(data){
$("#myForm").html(data);
},
error:function (){}
});
return true;
}
</script>
</head>
<body>
<h2>Contact Form</h2>
<form class="form" action="" method="post">
<p class="name">
<div id="myForm">
<input type="text" name="fname" id="fname"/>
<label for="fname">Name</label>
</p>
</div>
<p class="submit" >
<input type="button" onclick="formSubmit();" value="Send"/>
</p>
</form>
</body>
</html>
Related
I am trying to auth google user in WebView, I found a good solution for these days, it works fine for google login, but I cannot disable dialog in other urls like (, sms: , smsto:)
Example Situation: User click on telephone number in my app, it will open the phone dial, but when he returns back.. there is a empty dialog window with close button, i use it for google login with JS.
How can i close this dialog message inside the shouldOverrideUrlLoading()? Or is there any better solution to not open other links in the dialog? How can i improve my code to solve my problem? Thank you guys!
package com.example.app;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.lang.reflect.Field;
import java.security.cert.X509Certificate;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class MainActivity extends Activity {
private WebView mWebView;
private String userAgent;
private Context contextPop;
private WebView webViewPop;
private AlertDialog builder;
#Override
#SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userAgent = System.getProperty("http.agent");
mWebView = findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setAppCacheEnabled(false);
webSettings.setAllowFileAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setUserAgentString(userAgent+ "com.example.app");
mWebView.clearCache(true);
// REMOTE RESOURCE
mWebView.loadUrl("https://example.eu/");
mWebView.setWebChromeClient(new CustomChromeClient());
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
contextPop = this.getApplicationContext();
// LOCAL RESOURCE
// mWebView.loadUrl("file:///android_asset/index.html");
}
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
final Context myApp = this;
class CustomChromeClient extends WebChromeClient {
#Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
webViewPop = new WebView(contextPop);
webViewPop.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String host = Uri.parse(url).getHost();
if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mms:") || url.startsWith("mmsto:"))
{
webViewPop.destroy();
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
startActivity(intent);
return true;
}
//Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
//view.getContext().startActivity(intent);
return false;
}
});
// Enable Cookies
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
if (android.os.Build.VERSION.SDK_INT >= 21) {
cookieManager.setAcceptThirdPartyCookies(webViewPop, true);
cookieManager.setAcceptThirdPartyCookies(mWebView, true);
}
WebSettings popSettings = webViewPop.getSettings();
// WebView tweaks for popups
webViewPop.setVerticalScrollBarEnabled(false);
webViewPop.setHorizontalScrollBarEnabled(false);
popSettings.setJavaScriptEnabled(true);
popSettings.setSaveFormData(true);
popSettings.setEnableSmoothTransition(true);
// Set User Agent
popSettings.setUserAgentString(userAgent + "Your App Info/Version");
// to support content re-layout for redirects
popSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
// handle new popups
webViewPop.setWebChromeClient(new CustomChromeClient());
// set the WebView as the AlertDialog.Builder’s view
builder = new AlertDialog.Builder(MainActivity.this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT).create();
builder.setTitle("");
builder.setView(webViewPop);
builder.setButton("Close", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
webViewPop.destroy();
dialog.dismiss();
}
});
builder.show();
builder.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(webViewPop);
resultMsg.sendToTarget();
return true;
}
#Override
public void onCloseWindow(WebView window) {
//Toast.makeText(contextPop,"onCloseWindow called",Toast.LENGTH_SHORT).show();
try {
webViewPop.destroy();
} catch (Exception e) {
Log.d("Webview Destroy Error: ", e.getStackTrace().toString());
}
try {
builder.dismiss();
} catch (Exception e) {
Log.d("Builder Dismiss Error: ", e.getStackTrace().toString());
}
}
#Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(myApp)
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.confirm();
}
})
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.cancel();
}
})
.setCancelable(false)
.create()
.show();
return true;
}
#Override
public boolean onJsAlert(WebView view, final String url, String message,
JsResult result) {
new AlertDialog.Builder(myApp)
.setMessage(message)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
})
.setCancelable(false)
.show();
result.cancel();
return true;
}
}
}
Background:
* Full Stack developer training (recently finished studies).
* Am not very (putting it mildly) Java savvy.
for the past couple of days I've been trying to make the tapping on a OneSignal notification open the app according to the URL stored in the notification payload.
What did work was:
* If the app is showing on the screen and you press the notification it works fine and opens it accordingly.
It does ALMOST work in the way that if the app is in the background and you press the notification it either:
1. Launches the app but on the main page
OR
2. Doesn't launch the app but when you actively go back to the app it shows the correct content (according to the URL of the notification)
Following is the code:
Thank you!
package app.web.hodaya;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OneSignal;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import org.json.JSONObject;
import static com.onesignal.OneSignal.sendTag;
import static com.onesignal.OneSignal.sendTags;
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
CalculateObject calcObject = new CalculateObject();
PassingStringThrough passString = new PassingStringThrough();
ExampleNotificationOpenedHandler notificationOpened = new ExampleNotificationOpenedHandler();
UpdateOneSignalSettingTags sendTag = new UpdateOneSignalSettingTags();
super.onCreate(savedInstanceState);
// OneSignal Initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
.init();
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://hodaya-app.firebaseapp.com/");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.addJavascriptInterface(passString, "ob1");
try {
this.getSupportActionBar().hide();
} catch (NullPointerException e) {
}
}
#Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
class PassingStringThrough {
#JavascriptInterface
public void passString(
String m, String m1, String n, String n1, String e, String e1,
String name, String name1, String gender, String gender1) {
sendTag(m, m1);
sendTag(n, n1);
sendTag(e, e1);
sendTag(name, name1);
sendTag(gender, gender1);
/* alternatively*/
// tags.put(m, m1);
// tags.put(n, n1);
// tags.put(e, e1);
// OneSignal.sendTags(tags);
Log.d("settingsPassedCorrectly", "I just got executed!" + m + m1 + n + n1 + e + e1 + name + name1 + gender + gender1);
}
}
class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
#Override
public void notificationOpened(OSNotificationOpenResult result) {
Log.i("OSNotificationPayload", "result.notification.payload.toJSONObject().toString(): " + result.notification.payload.toJSONObject().toString());
JSONObject data = result.notification.payload.additionalData;
String customKey;
if (data != null) {
customKey = data.optString("tryli", null);
// if (customKey != null)
Log.i("DeepLinkToCustomkey", "customkey set with value: " + customKey);
WebView webView1;
// setContentView(R.layout.activity_main);
webView1 = findViewById(R.id.webView);
webView1.setWebViewClient(new WebViewClient());
webView1.loadUrl(customKey);
// WebView webView = null;
}
I wrote a simple cordova plugin which displays an alert.
JS file: alert.js
module.exports = {
alert: function(title, message, buttonLabel, successCallback) {
cordova.exec(successCallback,
null, // No failure callback
"Alert",
"alert",
[title, message, buttonLabel]);
}
};
Java File: Alert.java
package com.acme.plugin.alert;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Alert extends CordovaPlugin {
protected void pluginInitialize() {
}
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
throws JSONException {
if (action.equals("alert")) {
alert(args.getString(0), args.getString(1), args.getString(2), callbackContext);
return true;
}
return false;
}
private synchronized void alert(final String title,
final String message,
final String buttonLabel,
final CallbackContext callbackContext) {
new AlertDialog.Builder(cordova.getActivity())
.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setNeutralButton(buttonLabel, new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
}
})
.create()
.show();
}
}
How do I call the alert function of alert.js from another js? And what parameter should i pass to map to successCallback??
according to cordova git for creating plugin see github page you can do it like this
Add the following code to wherever you need to call the plugin functionality:
cordova.plugins.<PluginName>.<method>();
where <PluginName> is your plugin name and <method> is your method.
package controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.sun.corba.se.spi.orbutil.fsm.Action;
import bean.Video;
import dao.Dao;
import daoimpl.daoImpl;
public class DisplayVideo extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Dao dao=new daoImpl();
String action=request.getParameter("action");
if(action.equals("display")){
ArrayList<Video>al=dao.getAllVideo();
//PrintWriter pw=response.getWriter();
Gson gson=new Gson();
String json = gson.toJson(al);
System.out.println(json);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
}
}
}
This is my servlet where im getting data in json format.
<html>
<head>
<script type="text/javascript" src='js/jquery.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
alert("on document ready");
$('#video').click(function(event) {
alert("on click");
$.post("Controller?action=display",
function (data) {
alert("key"+data);
var json = data;
alert("value"+json);
$.each(json, function(key,value) {
alert("key1"+value);
var v ="<a href=${pageContext.request.contextPath}/videos/"+value.videoUrl+"target='blank'>"+value.videoUrl+"</a>";
$(v).appendTo($content);
});
});
});
});
</script>
</head>
<body>
<div id='content'>
<button id="video">Play</button>
</div>
</body></html>
This my sucess.jsp file from here control goes to servlet and get data in json format from database i have only save video name c.mp4,java.mp4 and cpp.mp4 in database also i have create a folder named videos in my webcontent folder in my project and save videos in that folder also.Response getting properly but after printing alert inside each their is nothing print on screen.my requirment is print that all names of video and onclick of link play video in iframe or in popup window.please help me i didnt know the tags which are used.Thanks in Advance.
i try to get my native android plugin on phonegap / cordova 3.0.0 running but i does not work,
the error from ripple:
Uncaught ReferenceError: torch is not defined
the call from the index.html
<button onclick="torch.shine(200);">dummy</button>
the plugin.xml
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Torch">
<param name="android-package" value="org.holzi.torch.Torch"/>
<param name="onload" value="true" />
</feature>
</config-file>
<js-module src="www/torch.js" name="Torch">
<clobbers target="torch" />
</js-module>
<source-file src="src/android/Torch.java" target-dir="src/org/holzi/torch" />
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
</config-file>
</platform>
the torch.js in the www folder of the plugin
var exec = require('cordova/exec');
/* constructor */
function Torch() {}
Torch.shine = function() {
exec(
function(result){ alert('ok: '+reply); },
function(err){ alert('Error: '+err); }
, "Torch", "shine", ['200']);
}
var torch = new Torch();
module.exports = torch;
and the Torch.java
/*
*/
package org.holzi.torch;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.os.Vibrator;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
public class Torch extends CordovaPlugin {
Camera camera;
Camera.Parameters Parameters;
public Torch() {
}
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("shine")) {
this.shine(20);
}
else {
return false;
}
// Only alert and confirm are async.
callbackContext.success();
return true;
}
public void shine(int time) {
//Torch torch = (Torch) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
//torch.shine(time);
camera = Camera.open();
Parameters p = camera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
}
}
i solved it, here the code if anyone else have the same problem:
the index with the javascript
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
// Empty
}
function shine(torchOn) {
navigator.notification.shine(torchOn);
}
function alertTorchError(message) {
alert(message);
}
</script>
</head>
<body>
<p> </p>
<p> </p>
<p>AN</p>
<p> </p>
<p> </p>
<p>AUS</p>
</body>
</html>
the js file with the exec
var exec = require('cordova/exec');
module.exports = {
shine: function(turnOn) {
exec(null, function(error) { alertTorchError(error); }, "Torch", "shine", [turnOn]);
},
};
and the java file
package org.apache.holzi.torch;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.content.pm.PackageManager;
/**
* This class provides access to the Torch on the device.
*/
public class Torch extends CordovaPlugin {
Camera camera;
Camera.Parameters Parameters;
boolean hasFlash;
/* Constructor */
public Torch() { }
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("shine")) {
hasFlash = this.cordova.getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if (!hasFlash) { callbackContext.error("no torch found"); }
else { this.shine(args.getBoolean(0));
}
}
else {
return false;
}
return true;
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
public void shine(boolean turnOn) {
if (camera == null) { camera = Camera.open(); }
if (turnOn) {
Parameters p = camera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
}
else {
Parameters p = camera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
}
}
}
I don't know my answer could help you or not ,but I encounter this error many times.The following is my code use cordova1.7.0 one years ago, this error not in your java code.
var Music = function() {};
Music.prototype.exec = function(action, args, successCallback,errorCallback) {
if (typeof successCallback !== "function") {
console.log("GetResource: successCallback is not a function");
return;}
console.log("JS function execute --OK");
if (errorCallback && (typeof errorCallback !== "function")) {
console.log("GetResource: errorCallback is not a function");
return;}
PhoneGap.exec(successCallback, errorCallback, "MusicPlugin", action, args);
};
navigator.music=window.music = new Music();
then, register the plugin in the XML file like this:
--your plugin package--
<plugin name="MusicPlugin" value="***.***.***.MusicPlugin"></plugin>
finally,you should invoke this variable after the doucument's 'deviceready' event.
document.addEventListener('deviceready',function());