Applying Cross Fade #4273
Answered
by
gAlleb
WittyWidget
asked this question in
Q&A
Applying Cross Fade
#4273
-
Hi @gAlleb, I want to apply radio = crossfade(fade_out=3., fade_in=3., duration=5., radio) for /play, /skip, and the whole system. However, when I attempt to apply this function and call the skip endpoint, it crashes. Audio # Declare the next_song variable to hold the next song's metadata
next_song = ref("")
# Set up check function that will check playlist for the next song and assign a string with data to `next_song` ref.
def check_next(r)
if request.resolve(r) then
m = request.metadata(r)
title = m["title"]
album = m["album"]
year = m["year"]
next_song := "#{title} - #{album} (#{year}) "
true
else
false
end
end
radio = playlist(audio_dir, mode="randomize", reload_mode="watch", check_next=check_next)
radio = mksafe(radio)
radio = crossfade(fade_out=3., fade_in=3., duration=5., radio)
current_title = ref("")
#current_artist = ref("")
current_albumartist = ref("")
def update_current_song(m) =
current_title := m["title"]
# current_artist := m["artist"]
current_albumartist := m["albumartist"]
end
radio.on_metadata(update_current_song)
def position() =
source.elapsed(radio) / source.duration(radio)
end
def remaining() =
time = source.remaining(radio)
seconds = string.of_int(digits=2, int(time mod 60.))
minutes = string.of_int(digits=2, int(time / 60.))
"#{minutes}:#{seconds}"
end Video...
background =
video.add_rectangle(
color=0xfcb900,
x=0 @ px,
y=5350 @ px,
height=50 @ px,
width={position() @ vw},
background
)
radio = source.mux.video(video=background, radio)
radio =
video.add_cover(
x=234 @ px,
y=2178 @ px,
width=1874 @ px,
height=1874 @ px,
default="./default-cover.jpg",
radio
)
... Harbor functions...
queue = request.queue(id="main_queue")
radio = fallback(track_sensitive=false, [queue, radio])
number_queue1 = ref(0)
# Endpoint to play a specific file
def play(request) =
fname = request.query["file"]
log.important("Requested file #{fname}.")
if file.exists(fname) then
log.important("File Request Accepted.")
queue.push.uri("#{fname}")
number_queue1 := number_queue1() + 1
q = queue.queue()
http.response(content_type="application/json; charset=UTF-8", status_code=200, data=json.stringify({status = "success", message = "Pushed: #{fname}.", pushed_track_count = number_queue1(), remaining_tracks_in_queue = list.length(q)}))
else
log.important("File Request Rejected: File Not Found.")
http.response(content_type="application/json; charset=UTF-8", status_code=404, data=json.stringify({status = "error", message = "Invalid file: #{fname}"}))
end
end
harbor.http.register.simple("/play", play, port=8007, method="GET")
# Skip
def skipper(_) =
radio.skip()
# JSON response data for successful skip
response_data = {
status = "success",
message = "The current song was skipped successfully!"
}
http.response(
content_type="application/json; charset=UTF-8",
status_code=200,
data=json.stringify(response_data)
)
end
harbor.http.register.simple(port=8007, "/skip", skipper)
... |
Beta Was this translation helpful? Give feedback.
Answered by
gAlleb
Dec 17, 2024
Replies: 1 comment 3 replies
-
Hi. Where exactly is your skip function? It should be before Your crossfade function should be after all of your fallbacks and queues. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crossfade always messes out with duration because it creates a new source all the way. You can try using
radio
source before crossfade to calculate progress bar. It may be not very precise but ok. Addradio_before_crossfade
, modifydef position()
and put crossfade function after:Also you have this code doubled in your config: