'sendCmd('save "' + playlistname + '"')' return? (Solved)

General discussion about RuneAudio. Do not post any support or feature requests here.

'sendCmd('save "' + playlistname + '"')' return? (Solved)

Postby irishwill2008 » 30 Nov 2016, 18:14

Hi there,

If i add a playlist that already exists. I.E: I add a playlist with the name test, i then try to add another playlist forgetting i already named one test but when i try add test it doesnt add it or replaces, not sure.

But i want it to display a message saying it already exists!
Thing is, it doesnt return true or false.. Not sure what it returns and cant find the save command reference. I checked command/index.php but not in there.

My code:
Code: Select all
$('#modal-pl-save-btn').click(function(){
   var playlistname = $('#pl-save-name').val();
   if (playlistname != "")
   {
      if (sendCmd('save "' + playlistname + '"'))
      {
              new PNotify({
                   title: 'Success',
                   text: 'Playlist Added',
                   icon: 'fa fa-check',
                   delay: 3000
             });
      }
      else
      {
         new PNotify({
            title: 'Error',
            text: 'Playlist Exists!',
            icon: 'fa fa-exclamation-circle',
            delay: 3000
         });
      }
   }
   else
   {
      new PNotify({
         title: 'Warning',
         text: 'Please Input A Name',
         icon: 'fa fa-exclamation-circle',
         delay: 3000
      });
   }
});
Last edited by irishwill2008 on 12 Dec 2016, 17:51, edited 1 time in total.
irishwill2008
 
Posts: 157
Joined: 26 Jul 2016, 14:49
Location: Ireland

Re: What does 'sendCmd('save "' + playlistname + '"')' retur

Postby surfninja » 01 Dec 2016, 16:41

I don't know python but a quick google found this.

you might want to check if the playlist exists before calling sendCmd to create a new list.
rAudio 1, Raspberry Pi 2B
rAudio 1, Raspberry Pi 4B
rAudio 1, Raspberry Pi Zero W
surfninja
 
Posts: 95
Joined: 13 Mar 2015, 22:06
Location: Minnesota

Re: What does 'sendCmd('save "' + playlistname + '"')' retur

Postby irishwill2008 » 01 Dec 2016, 17:02

SurfNinja, didnt think of that! What a great idea xD Will give that a shot, i could use some JS to check if it exists or not anyway ;) Great call on the file check!

I was just doing a simple fail / success check guessing the system knows it encounters the issue - failing the command but honestly dont know what it returns so..

Thanks!
irishwill2008
 
Posts: 157
Joined: 26 Jul 2016, 14:49
Location: Ireland

Re: What does 'sendCmd('save "' + playlistname + '"')' retur

Postby hondagx35 » 01 Dec 2016, 22:49

Hi,

Rune Audio is a client server application and nearly all is done asynchronous.

An example to explain synchronous versus asynchronous:
You are calling your local dealer to ask him if a special product is available.

synchronous:
- you: "Hello, do you have that green round shiny thing available?"
- he: "Sorry i have to check this, please wait"
- you: waiting, waiting ............... hmm .... waiting
- he: "Sorry we only have a blue round dull thing."

asynchronous:
- you: "Hello, do you have that green round shiny thing available?"
- he: "Sorry i have to check this, please wait. Will call you back soon!"
- you: doing something else until he calls back
- he: "Sorry we only have a blue round dull thing."

Saving a playlist is done by passing "mpc save playlistname" to

Code: Select all
function sendCmd(inputcmd) {
    $.ajax({
        type: 'GET',
        url: '/command/?cmd=' + inputcmd + '&clientUUID=' + GUI.clientUUID,
        cache: false
    });
}


You have to use the callback mechanism to get a response.
This may look like this

Code: Select all
function notify_user(result) {
   if (!result.match("^OK")) {
        new PNotify({
            title: 'Error',
            text: result,
            icon: 'fa fa-exclamation-circle',
            delay: 3000
        });
    }
}

// send a MPD playback control command
function sendCmd(inputcmd) {
    $.ajax({
        type: 'GET',
        url: '/command/?cmd=' + inputcmd + '&clientUUID=' + GUI.clientUUID,
        cache: false,
        success: notify_user
    });
}


Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: What does 'sendCmd('save "' + playlistname + '"')' retur

Postby surfninja » 02 Dec 2016, 16:30

Frank, your example is very, very good. Danke! It is always good to know that how the asynchronous communications work through mpc (mpd's client) and not through the file system.
rAudio 1, Raspberry Pi 2B
rAudio 1, Raspberry Pi 4B
rAudio 1, Raspberry Pi Zero W
surfninja
 
Posts: 95
Joined: 13 Mar 2015, 22:06
Location: Minnesota

support RuneAudio Donate with PayPal


Return to General discussion

Who is online

Users browsing this forum: No registered users and 2 guests