I thought this would be simple.

I have a web page that returns the filename of an MP3 file.  Each time
LiquidSoap needs to play a song, I want it to ask the web page for the
filename.

I am using V1.0.1

The script works.  EXCEPT, it plays each song TWICE.  It asks the server
for a name, plays that file, then plays it again, and then asks the server
for another file.

I know it isn't asking the server again, because I log each time the name
is requested.

I also know that the 'on_track' function gets executed twice, since the
server sees the notice that the song has started.

Any suggestions?

Here is my script:

#!/usr/bin/liquidsoap
# This is the basic LiquidSoap startup script.
# 1) It starts a blank source to a dummy output so that liquidsoap stays
running
#    and doesn't use a lot of CPU looking for stuff to play
# 2) It creates two server commands:
#    audiobox.start - this will create the getNextSongFilename playlist and
the output.alsa
#    audiobox.stop - this shuts down the playlist and the output
# The code is based on the dynamic playlist sample from the documentation

# Put the log file in some directory where you have permission to write.
#set("log.file.path","./liquidtesting.log")
# Turn off file logging during initial testing
set("log.file",false)
# Print log messages to the console,
set("log.stdout", true)
# Use the telnet server for requests while testing
set("server.telnet", true)
# Need to use external address to listen on, so we can talk from external
set("server.telnet.bind_addr","192.168.0.140")

# This will give liquidsoap something to do while we wait for the telnet
commands
output.dummy(blank())

# First, we create a list referencing the the playlist and the output:
sourceAndoutput = ref []

# We want to capture the filename when we start playing a song.
# This way, we can find the index of the current song in case we restart
node.
currentFile=ref interactive.string("fileName","")

# So we can change the volume
v = interactive.float("volume", 1.)

def track_filename(m) =
  # Grab the current filename when the track changes
  ignore(http.get("http://localhost:3000/songStarted";))
  currentFile := interactive.string("fileName",m["filename"])
end

# Create a function to create the playlist source and output it.
def create_playlist(ignore) =
  # The playlist source
  s = playlist(id="thelist",mode="normal", reload=1, reload_mode="rounds","
http://localhost:3000/getNextSongFileName";)
  s = on_track(id="thelist",track_filename,s)
  s = amplify(v, s)

  #The output device might have to change depending on your configuration
  output = output.alsa(id='localAudio', device="hw: Set",fallible=true,s)

  # Save the playlist and the output to the array
  sourceAndoutput :=
      list.append( [s,output],
                    !sourceAndoutput )
  "Created!"
end

# And a function to destroy the playlist and output we created
def destroy_playlist(ignore) =
  list.iter(source.shutdown, !sourceAndoutput)
  # The list is now empty
  sourceAndoutput := []
  # And return
  "Gone!"
end


# Now we register the telnet commands:
server.register(namespace="audiobox",
                description="Start asking for songs to play.",
                usage="start ",
                "start",
                create_playlist)
server.register(namespace="audiobox",
                description="Stop asking for songs to play.",
                usage="stop ",
                "stop",
                destroy_playlist)
------------------------------------------------------------------------------
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to