How does media player play next work?

Just after some advice about playing audio files in a sequence (ie play file one, then when its played, play file two).

I have been playing with the Enqueue option but not getting the results expected.

Example:
I play this:

alias: Play Dooong Downstairs
action: media_player.play_media
metadata: {}
data:
  media:
    media_content_id: media-source://media_source/local/audio/bell_tower.mp3
    media_content_type: audio/mpeg
    metadata:
      title: bell_tower.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
        - media_content_type: ""
          media_content_id: media-source://media_source/local/audio
      browse_entity_id: media_player.ma_kitchen
  enqueue: play
target:
  entity_id:
    - media_player.ma_kitchen

I want to play another file AFTER the previous one has played, so I run:

action: media_player.play_media
metadata: {}
data:
  media:
    media_content_id: media-source://media_source/local/audio/latest_abc_news_bulletin.mp3
    media_content_type: audio/mpeg
    metadata:
      title: latest_abc_news_bulletin.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
        - media_content_type: ""
          media_content_id: media-source://media_source/local/audio
      browse_entity_id: media_player.ma_kitchen
  enqueue: next
target:
  entity_id:
    - media_player.ma_kitchen

When I run the second play_media… it doesn’t play (with enqueue: next). If I try to just play it (enqueue: play)… it plays over the top of the previous one. I’ve put delays in between as well.

Anyone know the secret to playing audio files to media players in sequence?

https://www.home-assistant.io/integrations/media_player/#action-media_playerplay_media

What type of player is this?

This is a home pod mini, coming from music assistant.

Why not put them in a playlist and get music assistant to play that playlist in your automation?

I might try that. When I’ve tried to play files in sequence, music assistant does not play the file I have specified… instead it finds a podcast it thinks I want to play and plays that instead.

This is something I have really struggled with for a while now. Tried all sorts of things, including wait conditions (for the player to go idle), enqueue options, delays but nothing really seems to work. But I’ll give this a try.

I see there are two options within music assistant:

I gather I try the audio folder because that is where the files are.

The problem I have found with creating a playlist in music assistant is there does not seem to be a way to play files in sequence, ie the order they should be played. There only seem to options to sort the items within the playlist by artist, album etc. Though there is a sort by position. Perhaps that relates to the order in which the files are added to the playlist.

I think this may be the go. Seems pretty obvious now you’ve mentioned it. One draw back is that there seems no way to re-order the tracks once they are in there. But for my purposes this looks very promising.

Thanks for taking the time to explain the ‘bleedin obvious’ to me :wink:. Been very useful.

Just rename your files

a.mp3
b.mp3

etc :slight_smile:

Not sure that works… think it only affects the displayed sort order rather than the play order. I’ve found I need place them into the list in sequence.

What i am trying to do is something like:

  1. Play an intro music clip / jingle,
  2. Run a TTS announcement with the weather details and forecast,
  3. Run an mp3 file containing the latest news bulletin that has been downloaded, and then,
  4. Go to a radio stream.

One after the other in sequence, without one over playing the audio clip(s) earlier in the sequence. Thought the enqueue in the play media action would help with that.

Got 1 & 2 working through chimeTTS, 3 & 4 remain challenging. I want the TTS to end before it goes onto playing the news clip and then the radio stream. Tried using the wait function (for the media player to go to idle before progressing to playing the news.mp3 file.

Thought about generating an mp3 file from 1 & 2 through chimeTTS say_url, renaming that in an automation (through a shell command) and putting that in a playlist. Problem is that chimeTTS outputs the file but does not return its name so that it could be renamed. Was going to try to add the stream to the playlist I created but the radio station I want is not in the browse / radio browser in Music Assistant, even though I have added it to the Radio section and can be found in the Home Assistant Radio Browser (probably explains why it can’t be played through a music assistant play media action).