Phone Remote Control Script for MM 3.0?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

DeathMetalSquad8790
Posts: 8
Joined: Wed Apr 01, 2009 8:19 pm

Phone Remote Control Script for MM 3.0?

Post by DeathMetalSquad8790 »

I recently downloaded Phone Remote Control 5.2 from the BlueShareware.com website, and it has support for Winamp playback. When i connected my phone through Bluetooth to the PRC 5.2 app, it gave me the options on my phone to select winamp among other options. I connected to winamp worked perfectly showed what was playing, the time of the song, the album art, etc. My question is, is there a script for MM 3.0 that i can use to add to the PRC 5.2 app so i can uninstall winamp and remote control MediaMonkey. I dont know what info you need but attached below is the script for WinAmp that comes directly from the PRC 5.2 app.

Code: Select all

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// VARIABLES
var brcActivate = 1, brcBegin = 2,  brcBack = 3, brcNext = 4, brcKeyPress = 5, brcKeyRelease = 6, brcIntegerInput = 7, brcTimer =  9;
var buttonStop = 1, buttonPlay = 2, buttonPause = 3;
var stIdle = 1,stHelp = 2,stRewind = 3,stForward = 4,stWait = 5,stMenu = 6,stArtistList = 7,stAlbumList = 8, stAlbumTrackList = 9;
var  emBrowseArtists = 0;
var wo = null;
var CRLF = "\r\n";
var timerInterval = 1000;
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Script Entry Point
StartScript();

function StartScript()
{
	//Initiate
	switch (BRCD.Action)
	{
		case brcActivate:
			BRC.SetStore(0,stIdle);
			leftSoftKeyText();
			break;	
		case brcBegin:
			BRC.startTimer(timerInterval);
			break;		
		default:
	}

	//Get state
	var state = BRC.GetStore(0);

	//make sure that Winamp is running
	if (!BRC.IsProcessRunning("winamp")) {
		winAmpNotRunning();
		return;
	}
	else
	{
		//WinAmp is running return from stWait if we did launch it!
		if(state == stWait)
		{
			BRC.SetStore(0,stIdle);
			state = stIdle;
		}
	}

	//Connect to Winamp
	var connected = connectToWinamp();
	if(connected == false)
	{
		stateWinampNotRunning();
		return;
	}

	//Start executing the state machine
	switch (state)
	{
		case stIdle:
			stateIdle();
			break;
		case stHelp:
			stateHelp();
			break;
		case stRewind:
			stateRewind();
			break;
		case stForward:
			stateForward();
			break;
		case stMenu:
			stateMenu();
			break;
		case stArtistList:
			stateArtistList();
			break;
		case stAlbumList:
			stateAlbumList();
			break;
		case stAlbumTrackList:
			stateAlbumTrackList();
			break; 
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ************************************** STATE MACHINE ************************************************
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State Winamp not running
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateWinampNotRunning()
{
	switch (BRCD.Action)
	{
		case brcBack:
			exit();
			break;	
		default:	
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State Idle
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateIdle()
{
	switch (BRCD.Action)
	{
		case brcActivate:
			update();
			break;
		case brcBack:
			exit();
			return;
		case brcNext:
			update();
			break;
		case brcTimer:
			update();
			break;
		case brcKeyPress:
			stateIdleKeyPress();			
			break;
		case brcKeyRelease:
		
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State Help
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateHelp()
{
	switch (BRCD.Action)
	{
		case brcBack:
			BRC.SetStore(0,stIdle);
			update();
			break;
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State Rewind
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateRewind()
{
	switch (BRCD.Action)
	{
		case brcTimer:
			changePosition(-4000);
			break;
		case brcKeyRelease:
		case brcBack:
		default:
			BRC.startTimer(timerInterval);
			BRC.SetStore(0,stIdle);
			break;
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State Forward
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateForward()
{
	switch (BRCD.Action)
	{
		case brcTimer:
			changePosition(4000);
			break;
		case brcKeyRelease:
		case brcBack:
		default:
			BRC.startTimer(timerInterval);
			BRC.SetStore(0,stIdle);
			break;
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State extra menu
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function stateMenu()
{
	switch (BRCD.Action)
	{
		case brcBack:
			BRC.SetStore(0,stIdle);
			update();
			break;
		case brcIntegerInput:
			menuInput();
			break;
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State list artists
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateArtistList()
{
	switch (BRCD.Action)
	{
		case brcBack:
			showExtraMenu();
			break;
		case brcIntegerInput:
			showArtistAlbums();
			break;
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State list albums of a artist
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateAlbumList()
{
	switch (BRCD.Action)
	{
		case brcBack:
			browseArtists();
			break;
		case brcIntegerInput:
			showArtistTrack();
			break;
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// State list tracks in a album
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateAlbumTrackList()
{
	switch (BRCD.Action)
	{
		case brcBack:
			browseArtists();
			break;
		case brcIntegerInput:
			showArtistPlayTrack();
			break;
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ***************************************** UPDATE DISPLAY ************************************************
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function update()
{
	//Get reference to playlist and mediaItem
	var playlist = wo.Playlist;
	var mediaItem = playlist.Item( playlist.position );

	//UPDATE TEXT	

	var text =  "";

	//New client then 4.0 support sending image and artwork 
	var modifier = "";
	if (BRC.phoneClientVersion >= 40)
	{
		var modifier =  "<im>";
	}	

	//Add playllist row
	text = text + "<s><le>" + playlist.position + " of " + playlist.Count + CRLF; 

	//Add track 
	text = text + "<b><sc>" + modifier + mediaItem.Title + CRLF; 

	//Add artist
	text = text + modifier + mediaItem.Artist + CRLF; 

	//Add Album
	text = text + mediaItem.Album + CRLF; 

	//Add space
	text = text + "<sp>" + CRLF; 

	//Add help info
	text = text + "<s>(* for help)" + CRLF;

	//UPDATE GRAPHIC

	if (BRC.phoneClientVersion >= 40)
	{
		updateArtWork(mediaItem);
	}

    BRC.go_PlayerPostion = wo.Position/1000;
	BRC.go_Duration = mediaItem.Length;
	BRC.go_Repeat = wo.Repeat;
	BRC.go_Shuffle = wo.Shuffle;
	
	//Set button status
	switch( wo.PlayState ) {
		case 1:
			BRC.go_Button = buttonPlay;
			break;
		case 3:
			BRC.go_Button = buttonPause;
			break;
		default:
			BRC.go_Button = buttonStop;
			break;
	}

	BRC.DisplayDialog(text);

}


// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ***************************************** HELP FUNCTIONS ************************************************
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function updateArtWork(mediaItem)
{

	try {

		BRC.go_DeleteImage = false;

		//Images are not named the same or stored at same location.
		//So a dirty solution! any.jpg instructs the server to take the first jpg in the folder
		BRC.go_ImagePathDD = mediaItem.Filename + "\\any.jpg";

        //If server fail to find that jpg use default one
		var artWork = null;
        artWork = BRC.userDataPath + "\\Profiles\\Img\\NoArtwork.jpg";
		BRC.go_ImagePathDD_Default = artWork;

	} catch( e ) {}
}

function stateIdleKeyPress()
{
	
	switch (BRCD.Key)
	{
		case "*":	
			showHelp();
			break;
		case "^":
			wo.Previous();	
			update();
			break;
		case "v":
			wo.Skip();
			update();
			break;
		case "<":
			changePosition(-4000);
			BRC.SetStore(0,stRewind);
			BRC.startTimer(200);
			break;
		case ">":
			changePosition(4000);
			BRC.SetStore(0,stForward);
			BRC.startTimer(200);
			break;
		case "f":
		case "ok":
			playOrPause();
			update();
			break;
		case "1":
			incVolume(-15);
			break;
		case "2":
			wo.StopPlayback();
			break;
		case "3":
			incVolume(15);
			break;
		case "4":
			if(wo.Shuffle == 0)
			{
				wo.Shuffle = 1;
			}
			else
			{
				wo.Shuffle = 0;
			}
			update();
			break;
		case "5":
			showExtraMenu();	
			break;
		case "6":	
			if(wo.Repeat == 0)
			{
				wo.Repeat = 1;
			}
			else
			{
				wo.Repeat = 0;
			}
			update();
			break;
		default:
	}
}

function showHelp()
{
	var text =  "";

	text=  text + "OK: Play/Pause" + CRLF;
	text=  text + "F: Play/Pause" + CRLF;
	text=  text + "<: Rewind" + CRLF;
	text=  text + ">: Forward" + CRLF;
	text=  text + "^: Previous track" + CRLF;
	text=  text + "v: Next track" + CRLF;
	text=  text + "1: Decrease volume" + CRLF;
	text=  text + "2: Stop" + CRLF;
	text=  text + "3: Increase volume" + CRLF;
	text=  text + "4: Toggle shuffle" + CRLF;
	text=  text + "5: Menu" + CRLF;
	text=  text + "6: Toggle repeat" + CRLF;
	
	BRC.SetStore(0,stHelp);
	BRC.DisplayText("Winamp", text);	
}

function connectToWinamp()
{
	//Get WinAMP player
	try {
		wo = new ActiveXObject( "ActiveWinamp.Application" );		
	} catch( e ) {
		BRC.DisplayDialog("Please install ActiveWinamp.");
		return false;
	}

	try {
		if( wo.MediaLibrary == null ) throw "ML required"
	} catch( e ) {
		BRC.DisplayDialog("Winamp \"Full\ version with Media Library is required.");
		return false;
	}

	return true;
}


function leftSoftKeyText()
{
	var text =  "";

	text=  text + "OK: Play/Pause" + CRLF;
	text=  text + "F: Play/Pause" + CRLF;
	text=  text + "<: Rewind" + CRLF;
	text=  text + ">: Forward" + CRLF;
	text=  text + "^: Previous track" + CRLF;
	text=  text + "v: Next track" + CRLF;
	text=  text + "1: Decrease volume" + CRLF;
	text=  text + "2: Stop" + CRLF;
	text=  text + "3: Increase volume" + CRLF;
	text=  text + "4: Toggle shuffle" + CRLF;
	text=  text + "5: Menu" + CRLF;
	text=  text + "6: Toggle repeat" + CRLF;

	BRC.SetLeftSoftKeyText(text);	
}

function exit()
{
	try 
	{
		wo = null;
		
		BRC.StopTimer();
		BRC.UnLoad();
	}
	catch (exception) {}
}

function playOrPause()
{
	try {
		if( wo.PlayState == 1 ) {
			wo.Pause();
		} else {
			wo.Play(); 
		}
	} catch( e ) {}		
}

function incVolume(inc)
{   
  
    var soundVolume = wo.Volume + inc;
    
    if (soundVolume < 0) {
        soundVolume = 0;
    } else if (soundVolume > 255) {
        soundVolume = 255;
    }
    
    wo.Volume = soundVolume;
}


function changePosition(inc)
{
	try {
		var playlist = wo.Playlist;
		var mediaItem = playlist.Item( playlist.position );

		var maxLen = mediaItem.Length;
		var pos = wo.Position;

		pos += inc;

		if(pos < 0) pos = 0;

		wo.SendMsg( 1024, pos, 106 );

	} catch( e ) {}
}

function winAmpNotRunning()
{

	switch (BRCD.Action)
	{
		case brcBack:
			exit();
			break;	
		case brcNext:
			BRC.LaunchFile("winamp");

			//go to wait state
			BRC.DisplayProgress("Launching...");
			BRC.SetStore(0,stWait);
			
			break;	
		case brcKeyPress:
				if(BRCD.Key == "f")
				{
					BRC.LaunchFile("winamp");

					//go to wait state
					BRC.DisplayProgress("Launching...");
					BRC.SetStore(0,stWait);
				} 
			break;	
		case brcActivate:
			BRC.DisplayDialog("Press OK to launch " +  CRLF + "<b>Winamp");
			break;	
		default:	
	}	
}

function showExtraMenu()
{
	var extraMenu = new Array(1);
	extraMenu[0] = "Browse Artists";
	
	BRC.SetStore(0,stMenu);
	showMenu("Winamp",extraMenu ,false);
}

function menuInput()
{
	switch (BRCD.IntInput)
	{
		case emBrowseArtists:
			browseArtists();
			break;
		default:
	}
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Show artist->Album->Track in the menu - BEGIN
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function browseArtists()
{

	// Get Library
	var mediaLibrary = wo.MediaLibrary;
    
	var artist_list = new Array();
	    
	var artists = new Array();
	var artistName;

	/**** Use cache auther of ActiveWinamp solution ****/

	var query = "";
	query = "(type = 0) && (artist ISNOTEMPTY)"
	var result = new VBArray( mediaLibrary.RunQueryArray( query ) );
	if (result.lbound() == 0) {
		return; // No result!
    }
	var ubound = result.ubound();
	
	// Check cached artists
	var readFromCache = 1;
	try {
		var artistCacheFileStream = fso.OpenTextFile("C:\winamp_artists.txt", 1, false );
		if( artistCacheFileStream != null ) {
			var cachedTrackCount = artistCacheFileStream.ReadLine();
			if( cachedTrackCount == ubound ) {
				while( true ) {
					var artistName = artistCacheFileStream.ReadLine();
					artist_list.push( artistName );
				}
			}
		}
	} catch( e ) {
		readFromCache = 0;
	} finally {
		if( artistCacheFileStream != null ) artistCacheFileStream.Close();	
	}
	
	if(artist_list.length == 0)
	{

		for (var i = result.lbound(); i <= ubound; i++)
		{
			var artistName = result.getItem(i).Artist;
			if(artistName.substring(0, 4) == "The ") artistName = artistName.substring(4)+", The";
			artists.push(artistName);
		
		}

		// Remove duplicate artists
		artists.sort();
		
		artist_list.push(artists[0]);
		var before = "";
		var now = "";
		var later = "";
		var len = artists.length;
		for (var j = 1; j < len; j++)
		{
			before = artists[j-1]
			now = artists[j];
			if (now.toLowerCase() != before.toLowerCase())
			{		
				artist_list.push(now);
			}			
		}

		// Save cache
		if(readFromCache == 0){
			try {
				var artistCacheFileStream = fso.CreateTextFile("C:\winamp_artists.txt", true );	// overwrite
				artistCacheFileStream.WriteLine(ubound);


				for( var e = new Enumerator( artist_list ); ! e.atEnd(); e.moveNext() ) {
					artistCacheFileStream.WriteLine( e.item());
				}
				
			} catch( e ) {
			} finally {
				if( artistCacheFileStream != null ) artistCacheFileStream.Close();
			}
		}	
	}

    if (artist_list.length == 0) {
		return;
    }

	BRC.SetStore(0,stArtistList);	
	BRC.SetObjStore(1, artist_list);	//Store artist list
    showMenu("Artists",artist_list,false);
}

function showArtistAlbums()
{

	//Get the list of artists displayed to user
	var artist_list = BRC.GetObjStore(1);

	//Get the selected artists
	var selected_artist = artist_list[BRCD.IntInput];

	var mediaLibrary = wo.MediaLibrary;
	var query = "(type = 0) && (artist = \"" + selected_artist + "\")";
	var tracks = new VBArray( mediaLibrary.RunQueryArray( query ) );
		
	var albums = new Array();
	for (var i = tracks.lbound(); i <= tracks.ubound(); i++)
	{
		var track = tracks.getItem(i);
		albums.push(track.Album);
	}

	// Remove duplicates
	var album_list = new Array();
	
	if (albums.length > 0)
	{
		albums.sort();
		album_list.push(albums[0]);
	}

	for (var j = 1; j < albums.length; j++)
	{
		if (albums[j] != album_list[album_list.length-1])
		{
			album_list.push(albums[j]);
		}
	}

	BRC.SetStore(0,stAlbumList);	
	BRC.SetObjStore(2, album_list);	//Store album list
	BRC.SetTextStore(1, selected_artist);	//Store artist
	showMenu("Albums",album_list,false);
}

function showArtistTrack()
{
	//Get the album list
	var album_list = BRC.GetObjStore(2);
	
	//Get the selected album
	var selected_album = album_list[BRCD.IntInput];

	//Get the selcted artist
	var selected_artist = BRC.GetTextStore(1);
        
	query = "(type = 0) && (album = \"" + selected_album + "\") && (artist = \"" + selected_artist + "\")";
	var mediaLibrary = wo.MediaLibrary;    
	var tracks = new VBArray( mediaLibrary.RunQueryArray( query ) );
   	
    var listItems = new Array();
    album_tracks = new Array();
	var sorted_tracks = new Array();
    var sorted_list =  new Array();
	
    for (var i = tracks.lbound(); i <= tracks.ubound(); i++)
    {
        var track = tracks.getItem(i);
		listItems.push( track.Title );
		album_tracks.push( track );
    }

	listItems.reverse();
	album_tracks.reverse();
	var n = 1;
	sorted_tracks[n-1] = album_tracks[n-1];
	sorted_list[n-1] = listItems[n-1];

	while (n < album_tracks.length) {
			 var m = n - 1;
			 var value = album_tracks[n].Track
			 while (m >= 0) {					
				var sortValue = sorted_tracks[m].Track
				if(sortValue > value){
					sorted_tracks[m+1] = sorted_tracks[m];
					sorted_list[m+1] = sorted_list[m];
					m = m - 1;				
				}
				else break;
			}
			sorted_tracks[m+1] = album_tracks[n];
			sorted_list[m+1] = listItems[n];
			n = n + 1;
	 }
	
	album_tracks = sorted_tracks;
	listItems = sorted_list;

    BRC.SetStore(0,stAlbumTrackList);	
	BRC.SetObjStore(3, album_tracks);	//Store list of tracks
	showMenu("Tracks",listItems,false);
}

function showArtistPlayTrack()
{

	//Get the album list
	var album_tracks = BRC.GetObjStore(3);

	//Get the selected track
	var selected_track = album_tracks[BRCD.IntInput];

	selected_track.Insert( wo.Playlist.Position );
	wo.Playlist.Position = wo.Playlist.Position + 1;
	wo.StopPlayback();
	wo.Play();
	var number = selected_track.Track;
	
	BRC.SetStore(0,stIdle);
	update();
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Show artist->Album->Track in the menu - END
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function showMenu(title,menu,sorted)
{

	//Send all elements but the last one!
	for (var i = 0; i < menu.length-1; i++)
    	{
		 if (sorted)
        		{
            		BRC.DisplaySortedMenu(title,menu[i],false);
        		}
		else
		{
			BRC.DisplayMenu(title,menu[i],false);
		}
	}

	//Send last element
	 if (sorted)
        	{
            	BRC.DisplaySortedMenu(title,menu[menu.length-1],true);
        	}
	else
	{
		BRC.DisplayMenu(title,menu[menu.length-1],true);
	}
}
Last edited by nohitter151 on Sat Dec 12, 2009 4:43 pm, edited 1 time in total.
Reason: Code should be displayed in [code] brackets
Peke
Posts: 18673
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Phone Remote Control Script for MM 3.0?

Post by Peke »

It should be fairly easy to support MediaMonkey by changing "Winamp" -> "MediaMonkey" like in

Code: Select all

   //Get state
   var state = BRC.GetStore(0);

   //make sure that Winamp is running
   if (!BRC.IsProcessRunning("MediaMonkey")) {
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
fbmmonkey
Posts: 1
Joined: Sun Feb 07, 2010 11:07 pm

Re: Phone Remote Control Script for MM 3.0?

Post by fbmmonkey »

Hi There,
it's not that simple... I tried!

is anyone interested in developing a script for this? I wish I was able to, but after spending some time looking at it, I am afraid I am not yet up to that level.

I am not looking for something overly complicated: would be more than enough seeing the album art, and current artist/album/title on the display of the phone, I guess a lot of people may be interested in a script like this!

Sending the commands shouldn't be any complicated, since mediamonkey supports global hotkeys.

If anyone has some interest in developing it, or helping me in doing so, it would be awesome!

Oh, the website of this remote controller may raise a "potential danger" alert since a couple of days ago for some reason. As far as I am concerned this is a mistake, I have been using it for a while and never had a problem, they have been out there for a few years, it would be quite unclever of them change policy all of the sudden... anyway I just wanted to make sure you don't blame me :P

Thanks all,

F.
Peke
Posts: 18673
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Phone Remote Control Script for MM 3.0?

Post by Peke »

Unfortunately I do not have bluetooth on my PC so that I can't help you much except in suggestions.

Example you wrote is in Java Script, is there possibility to write control in VBScript where I can help you much more?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
fbmmonkeys

Re: Phone Remote Control Script for MM 3.0?

Post by fbmmonkeys »

Hi!
Sorry but it wasn't me the one who sent out the java script... despite, it is only the one that comes bundled with the remote control software for monitoring and using winamp, I wouldn't be able to write all that by myself I am afraid... I should be more than able to do editing and tweaking tho.

Any help wellcome :)

thanks!
Peke
Posts: 18673
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Phone Remote Control Script for MM 3.0?

Post by Peke »

Sorry, my mistake.
You should try to start on tweaking and I'll try to answer any question/problem you encounter.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Post Reply