This section explains how to implement XMTV Player into your android application. Its not exactly an API, its a way how to do some checks and start player with intent.
Using XMTV Player in WebView – added href xmtv:// handler with base64 encoded data
On your mobile web page you can add <a> tag in following format xmtv:// link, for example we use www.base64encode.org for encoding and www.base64decode.org/ for decoding data with UTF-8 charset.
<a href="xmtv://base64url">TEST LINK</a>
<a href="xmtv://base64url$base64Title">TEST LINK</a>
Example:
LINK <a href="xmtv://cnRtcDovLyRPUFQ6cnRtcC1yYXc9cnRtcDovL3J0bXAuemVyb2Nhc3QudHY6MTkzNS9saXZlP3Q9eHdxUmhuNWRDIHBsYXlwYXRoPWNuIHN3ZlVybD1odHRwOi8vY2RuLmlicm9kLnR2L3BsYXllci5zd2YgZmxhc2h2ZXI9V0lOXDIwMjAxMiwwLDAsNzcgdGltZW91dD0xNSB0b2tlbj04OTY0MzE2ZWM4NzcyZGZhIGxpdmU9MSBzd2ZWZnk9MSBwYWdlVXJsPWh0dHA6Ly96ZXJvY2FzdC50di8=">TEST LINK</a> LINK with TITLE <a href="xmtv://cnRtcDovLyRPUFQ6cnRtcC1yYXc9cnRtcDovL3J0bXAuemVyb2Nhc3QudHY6MTkzNS9saXZlP3Q9eHdxUmhuNWRDIHBsYXlwYXRoPWNuIHN3ZlVybD1odHRwOi8vY2RuLmlicm9kLnR2L3BsYXllci5zd2YgZmxhc2h2ZXI9V0lOXDIwMjAxMiwwLDAsNzcgdGltZW91dD0xNSB0b2tlbj04OTY0MzE2ZWM4NzcyZGZhIGxpdmU9MSBzd2ZWZnk9MSBwYWdlVXJsPWh0dHA6Ly96ZXJvY2FzdC50di8=$VEVTVCBMSU5L">TEST LINK</a>
this feature is requested by SuperUser
How to build XMTV Player Addon:
You can check sample project on GitHub: https://github.com/anopid/weebtv
Intent definition for playing back videos through XMTV Player:
How to check is XMTV Player is installed on android device:
// after version 2018.1.16 you need to change "com.xmtvplayer.watch.live.streams" to "com.xmtex.videoplayer.ads"
public static boolean isXMTVPlayerAvailable(Context context) {
PackageManager pm = context.getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo("com.xmtvplayer.watch.live.streams", PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed ;
}
Build dialog if XMTV Player is not installed
/**
* Build dialog which will redirect user to google play store
* @param context
* @param Title - "Information"
* @param Message - Message to notify user
* @param url - XMTV Market url
*/
public static void XMTVInstall(final Context context, String Title, String Message, final String url){
new AlertDialog.Builder(context)
.setTitle(Title)
.setMessage(Message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.setData(Uri.parse(url));
context.startActivity(intent);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_info)
.show();
}
/**
* Berore play media
*/
if (!isXMTVPlayerAvailable(context)){
String url = "market://details?id=com.xmtvplayer.watch.live.streams";
String message "to play this stream you need XMTV, pressing OK you will be redirected to market";
String Title = "Information";
XMTVInstall(context, Title, message, url);
}
Play single media
/**
* @param Title - Media Name
* @param uri - path/url to media
*/
public void XMTVPlayerPlayUri(String Title,String uri){
Bundle bnd = new Bundle();
bnd.putString("path", uri);
bnd.putString("name", Title);
bnd.putInt("ExitTime", TimeInSeconds); // not required
try{
Intent intent = new Intent();
//intent.setClassName("com.xmtex.videoplayer.ads","org.zeipel.videoplayer.XMTVPlayer");
ComponentName cName = new ComponentName("com.xmtex.videoplayer.ads","org.zeipel.videoplayer.XMTVPlayer");
intent.setComponent(cName);
intent.putExtras(bnd);
startActivityForResult(intent, 100);
} catch (Exception e){
try {
Intent intent = new Intent();
intent.setClassName("com.xmtvplayer.watch.live.streams","org.zeipel.videoplayer.XMTVPlayer");
intent.putExtras(bnd);
startActivityForResult(intent, 100);
} catch (Exception noplayerfound){
// notify user to download latest player
}
}
}Play single media with Sharing, Favorites and Buffer line hidden, exit with single click
WARNING!!! Parameters “HiddenMode”, “HideBufferLine” and “NoExitPrompt” are case-sensitive!
/**
* @param Title - Media Name
* @param uri - path/url to media
*/
public void XMTVPlayerPlayUri(String Title,String uri){
Bundle bnd = new Bundle();
bnd.putString("path", uri);
bnd.putString("name", Title);
bnd.putBoolean(“HiddenMode”, true); // Hide Share & Favorite button from player
bnd.putBoolean(“NoExitPrompt”, true); // Exit from player with one click of back button
bnd.putBoolean(“HideBufferLine”, true); // Hide yellow buffer status line
Intent intent = new Intent();
intent.setClassName("com.xmtvplayer.watch.live.streams","org.zeipel.videoplayer.XMTVPlayer");
intent.putExtras(bnd);
startActivityForResult(intent, 100);
}Play single media with Banner and/or Video ads (Monetize)
/**
* @param Title - Media Name
* @param uri - path/url to media
*/
public void XMTVPlayerPlayUri(String Title,String uri){
// [String] adszone - get zone id after filling form.
// [Integer] adstime - how long ad will stay before user will able to close it, value is in seconds.
Bundle bnd = new Bundle();
bnd.putString("path", uri);
bnd.putString("name", Title);
bnd.putString("adszone", "15E56089-CB15-4AA7-8D1B-574E899DE009"); // change adszone with your own id.
bnd.putInt("adstime",30);
Intent intent = new Intent();
intent.setClassName("com.xmtvplayer.watch.live.streams","org.zeipel.videoplayer.XMTVPlayer");
intent.putExtras(bnd);
startActivityForResult(intent, 100);
}Play PLAYLIST
/**
* @param Title - Play List Name
* @param StringJSArray - Converted JSArray to String with playlist data [{"title":"title 1","uri":"uri 1"},{"title":"title 2","uri":"uri 2"},{"title":"title 3","uri":"uri 3"}]
*/
public void XMTVPlayerPlayList(String Title,String StringJSArray){
Bundle bnd = new Bundle();
bnd.putString("data", StringJSArray);
bnd.putString("name", Title);
try{
Intent intent = new Intent();
//intent.setClassName("com.xmtex.videoplayer.ads","org.zeipel.videoplayer.XMTVPlayer");
ComponentName cName = new ComponentName("com.xmtex.videoplayer.ads","org.zeipel.videoplayer.XMTVPlayer");
intent.setComponent(cName);
intent.putExtras(bnd);
startActivityForResult(intent, 100);
} catch (Exception e){
try{
Intent intent = new Intent();
intent.setClassName("com.xmtvplayer.watch.live.streams","org.zeipel.videoplayer.XMTVPlayer");
intent.putExtras(bnd);
startActivityForResult(intent, 100);
} catch (Exception eNoPlayerFound){
// no player found
}
}
}