Hello, I have an issue with my code regarding the part where it’s supposed to automatically play audio tracks randomly. However, I’m encountering errors. Could you please help me? Thank you.
using { Timer, Random }
using { fortnite.devices.audio_player_device }
class AudioPlayerDevice extends creative_device:
var musicSounds: [string] = [
“/Game/playmusic/Track1”,
“/Game/playmusic/Track2”,
“/Game/playmusic/Track3”
]
var audioPlayer: audio_player_device = audio_player_device{}
on Begin():
self.playRandomMusic()
playRandomMusic():
if length(self.musicSounds) > 0:
var randomIndex = Random.intInRange(0, length(self.musicSounds) - 1)
var selectedSound = self.musicSounds[randomIndex]
self.audioPlayer.play(selectedSound)
var soundDuration = self.getSoundDuration(selectedSound)
Timer.setTimer(soundDuration, self.playRandomMusic)
getSoundDuration(sound: string): float:
match sound:
"/Game/playmusic/Track1" => return 1.02 * 60
"/Game/playmusic/Track2" => return 3 * 60
"/Game/playmusic/Track3" => return 3 * 60
else => return 30.0
var musicDevice: AudioPlayerDevice = AudioPlayerDevice{}
if(FirstAudioPlayer := musicDevice.musicSounds[0]):
FirstAudioPlayer.play()