Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 10
  1. #1
    Junior Member
    Join Date
    Jan 2016
    Posts
    11

    Save the 'state' of a player

    Hi all,

    I'm writing a small python app and I'm slowly re-learning the cli syntax (albeit with the rpc/json interface). The idea is to save the 'state' of a player ( i.e. the current song, playlist, volume, mode, repeat, shuffle, etc), then programatically change the state (say, adjust the volume and issue an audio message) then restore the state of the player. Something like:

    Code:
    server = LMSServer(host,port)
    players = server.get_players()
    
    for player in players:
        player.saveState()
    
    for player in players:
        player.volume(30)
        player.repeat(0)
        player.playlist_play(itemToPlay)
    
    for player in players:
        player.restoreState()
    Before I go too far into this, can anyone advise how feasible this is?

    To save the current 'state' of a player (i.e. the playlist, current track, volume, repeat, mode, etc) I can use the 'status' command:

    Code:
    curl -X POST -d '{"id":0,"params":["00:04:20:27:b4:00", ["status", "-", "20", "tags:u"]],"method":"slim.request"}' http://localhostm:9000/jsonrpc.js
    {"params":["00:04:20:27:b4:00",["status","-","20","tags:u"]],"method":"slim.request","result":{"playlist_loop":[{"playlist index":8,"url":"file:///data/music/Bing%20Crosby/Bing%20Crosby%27s%20Christmas%20Classics/09%20-%20Frosty%20the%20Snowman.mp3","id":1264,"title":"Frosty the Snowman"},{"title":"I Wish You a Merry Christmas","url":"file:///data/music/Bing%20Crosby/Bing%20Crosby%27s%20Christmas%20Classics/10%20-%20I%20Wish%20You%20a%20Merry%20Christmas.mp3","id":1265,"playlist index":9},{"title":"The Christmas Song","url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/01%20-%20The%20Christmas%20Song.mp3","id":9183,"playlist index":10},{"id":9184,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/02%20-%20Deck%20the%20Halls.mp3","title":"Deck the Halls","playlist index":11},{"id":9185,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/03%20-%20Frosty%20the%20Snowman.mp3","title":"Frosty the Snowman","playlist index":12},{"id":9186,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/04%20-%20I%20Saw%20Three%20Ships.mp3","title":"I Saw Three Ships","playlist index":13},{"title":"Buon Natale (Means Merry Christmas to You)","id":9187,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/05%20-%20Buon%20Natale%20(Means%20Merry%20Christmas%20to%20You).mp3","playlist index":14},{"playlist index":15,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/06%20-%20Adeste%20Fidelis.mp3","id":9188,"title":"Adeste Fidelis"},{"playlist index":16,"id":9189,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/07%20-%20O%20Little%20Town.mp3","title":"O Little Town"},{"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/08%20-%20The%20Little%20Boy%20That%20Santa%20Claus%20Forgot.mp3","id":9190,"title":"The Little Boy That Santa Claus Forgot","playlist index":17},{"playlist index":18,"title":"O Tannenbaum","url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/09%20-%20O%20Tannenbaum.mp3","id":9191},{"playlist index":19,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/10%20-%20The%20First%20Noel.mp3","id":9192,"title":"The First Noel"},{"playlist index":20,"title":"The Little Christmas Tree","id":9193,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/11%20-%20The%20Little%20Christmas%20Tree.mp3"},{"playlist index":21,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/12%20-%20Hark%20the%20Herald%20Angels%20Sing.mp3","id":9194,"title":"Hark the Herald Angels Sing"},{"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/13%20-%20The%20Happiest%20Christmas%20Tree.mp3","id":9195,"title":"The Happiest Christmas Tree","playlist index":22},{"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/14%20-%20Joy%20to%20the%20World.mp3","id":9196,"title":"Joy to the World","playlist index":23},{"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/15%20-%20O%20Holy%20Night.mp3","id":9197,"title":"O Holy Night","playlist index":24},{"playlist index":25,"id":9198,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/16%20-%20Caroling,%20Caroling.mp3","title":"Caroling, Caroling"},{"id":9199,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/17%20-%20A%20Cradle%20in%20Bethlehem.mp3","title":"A Cradle in Bethlehem","playlist index":26},{"playlist index":27,"id":9200,"url":"file:///data/music/Nat%20King%20Cole/The%20Christmas%20Album%201997/18%20-%20Away%20in%20a%20Manger.mp3","title":"Away in a Manger"}],"sync_master":"00:04:20:26:ab:08","duration":136.106,"mode":"play","can_seek":1,"digital_volume_control":1,"playlist_cur_index":"8","power":1,"player_name":"Lee's Room","playlist shuffle":0,"player_ip":"10.10.60.107:38893","sync_slaves":"00:04:20:27:b4:00","mixer volume":35,"rate":1,"player_connected":1,"time":123.344784011841,"playlist mode":"off","playlist_timestamp":1606834134.89273,"signalstrength":70,"playlist repeat":2,"seq_no":"688","playlist_tracks":116},"id":0}
    I believe this gives me everything regarding the player's configuration but the playlist is difficult to make sense of, depending on the values of shuffle and repeat. It is also assumes that I know the playlist length to feed into itemsPerResponse but I can get this with 00:04:20:27:b4:00 playlist tracks ?.

    Then, I need to restore the state of a player for which there isn't an equivalent to the 'status' command... this is fine, I can restore each setting.

    BUT, this is getting more complicated than I initially expected and I figured it was worth asking if there is a better way.

    Thanks!
    Last edited by rdb; 2020-12-01 at 08:17.
    Randy
    2xBoom, 3xRadio, 1xDuet, 1xSoundbridge

  2. #2
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,505

    Save the 'state' of a player

    > I'm writing a small python app and I'm slowly re-learning the cli syntax
    > (albeit with the rpc/json interface). The idea is to save the 'state' of
    > a player ( i.e. the current song, playlist, volume, mode, repeat,
    > shuffle, etc), then programatically change the state (say, adjust the
    > volume and issue an audio message) then restore the state of the player.


    Please help me understand why you'd want to backup/restore state outside
    LMS? It could be as simple as backing up some config files...

    --

    Michael

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,399
    I think this is to interrupt the programming ... e.g.
    Track 10 of a 15 track playlist is 30% played ....
    Door bell rings
    Save player state
    Announce that there is someone at the door
    Restore player state
    resume play

    If that is what is required ... then take a look at LMS Announce and I think some other add-ons - e.g. for Home Assistant

    https://forums.slimdevices.com/showt...-notifications
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

  4. #4
    Junior Member
    Join Date
    Jan 2016
    Posts
    11
    Quote Originally Posted by mherger View Post
    >
    Please help me understand why you'd want to backup/restore state outside
    LMS? It could be as simple as backing up some config files...
    Indeed, as Paul stated, this is simply to 'interrupt the programming' and then restore it. I'll take a look at the LMS Announce.
    Randy
    2xBoom, 3xRadio, 1xDuet, 1xSoundbridge

  5. #5
    jvromans@squirrel.nl
    Guest

    Save the 'state' of a player

    On Tue, 1 Dec 2020 15:30:05 +0000, Paul Webster
    <Paul.Webster.9t7ljc (AT) no-mx (DOT) forums.slimdevices.com> wrote:

    > I think this is to interrupt the programming ... e.g.
    > Track 10 of a 15 track playlist is 30% played ....
    > Door bell rings
    > Save player state


    Eh... Pause?

    Or do I misunderstand completely...

  6. #6
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,505

    Save the 'state' of a player

    > Indeed, as Paul stated, this is simply to 'interrupt the programming'
    > and then restore it. I'll take a look at the LMS Announce.


    Did you look into the "playlist preview" command?

    --

    Michael

  7. #7
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,399
    Quote Originally Posted by jvromans@squirrel.nl View Post
    Or do I misunderstand completely...
    Pausing is not the problem ... it is the resuming afterwards when the announcement has been played that is the problem.
    See the plugin that I linked to for some things that can go wrong.
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

  8. #8
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,399
    Quote Originally Posted by mherger View Post
    > Indeed, as Paul stated, this is simply to 'interrupt the programming'
    > and then restore it. I'll take a look at the LMS Announce.


    Did you look into the "playlist preview" command?

    --

    Michael
    This is a function that does not come up often on the forum ... so would be good to see if playlist preview turns out to be the solution.
    Old thread where it was not resolved
    https://forums.slimdevices.com/showt...h-wipePlaylist
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

  9. #9
    Junior Member
    Join Date
    Jan 2016
    Posts
    11
    Quote Originally Posted by Paul Webster View Post
    This is a function that does not come up often on the forum ... so would be good to see if playlist preview turns out to be the solution.
    Old thread where it was not resolved
    https://forums.slimdevices.com/showt...h-wipePlaylist
    Thanks, I will look at playlist preview. Looking through LMSannounce, this may to be the approach used (I'm rusty at reading Perl). The other issues are comparably minor. You need to handle the volume, repeat and shuffle and (in my case) deal with synchronized players. Eg, if repeat=1 then the 'announcement' playlist is repeated. Likewise, if shuffle=1 then the 'announcement' playlist is scrambled if you include pre/post sounds. With players in many areas of our house, I may try and synchronize playback...
    Randy
    2xBoom, 3xRadio, 1xDuet, 1xSoundbridge

  10. #10
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,399
    For sync .... you could use the Group Players plugin (I think it was not available when LMS Announce was written) to create an Announce Group and then send it there.
    But I suspect you might still have to iterate through the players to get/restore state unless this Preview function does some magic.
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •