Simultaneous output from libspotify - spotify

I'm curious if it's possible to use libspotify to play multiple files at once, through different outputs. I want to be able to play one song through speakers and jump around through other songs on headphones when djing.
Does anyone know if this is possible? If it's only doable with offline files I'm ok with that. I'd even be fine with having two separate processes running libspotify if that's what works.
Thanks!

No, it is not possible. Libspotify will stop the playback of the first track and call the play_token_lost() callback.

Related

Issues with playing audio over voice channel; audio is truncated and each file is progressively more delayed

The end goal: I'm creating a discord bot built for Final Fantasy XIV raiding. You simply tell the bot when you pull the boss and it follows a pre-defined timeline that warns everyone of each mechanic shortly before it happens. In short: It plays a pre-defined list of audio files at pre-defined times after receiving a !start command.
The good news is that the audio is playing.
The bad news is...complicated.
There are two issues and I have a feeling they're related. The first issue is that, no matter what audio file I play, the last bit (about 0.5s) gets cut off. I gave it an audio file that says "Tank buster soon" and it played "Tank buster s-" then cut out. Up until now, I've been working around this by simply adding one second of silence on the end of every sound file. It's been working. It's still getting truncated, of course, it's just that it's truncating silence.
The second issue is that, after playing one audio file, the next audio file has a short delay between when the bot tries to start playing it, and when the audio actually comes out. (In discord, I can see this as the bot cueing up their "mic" a short time before it starts playing audio.) This delay gets progressively worse with every file played, to the point where it's literally several seconds delayed. (When the delay is severe enough, I see the bot cue up for about a second, un-cue, and then re-cue when the delay finally finishes)
The code doing most of the work is as follows:
//timeline() is called once per second by a setInterval() object, while the fight is active.
function timeline()
{
tick++;
var len = callouts.length;
for (var i = 0; i < len; i++)
{
if (tick == callouts[i]["time"])
{
dispatcher[dispatcherIndex] = voiceConnection.playFile(callouts[i]["file"]);
dispatcherIndex++;
activeChannel.send(callouts[i]["message"]);
}
}
} //end timeline()
Discord.js documentation mentions that it prefers node-opus to be used for voice functionality, but that opusscript will also work. I cannot seem to install the former, so I am using the latter.
EDIT: I've found a workaround for now. The progressive delay is "reset" when the bot leaves and rejoins voice, so I've simply made it do so when it finishes playing an audio file. Strictly speaking, it works, but I'd still like a "proper" solution if possible.
Installing git (why the heck have I not installed git long ago?) ultimately turned out to be the correct catalyst. That, as mentioned, let me install discord.js master branch, which handles voice better. After a couple ffmpeg-related hiccups, I now have the bot playing complete audio files with no delay, with no workarounds required. Everything's working great now!

LabView playing more than one sound at the time

I'm using event structure and want to do some like Launchpad.
Numeric keyboard have for each number added a sound.
Problem is, that when I press number example one, the program is waiting when the music stop play and next I can press example number four.
Is it possible, to play sounds from 3 key's at the same time using event structure ?
I put the files online here and added screenshots below. Block diagram:
Front panel:
Working Solution
I think I got this working much more easily than I expected using the Play Sound File VI under the Graphics and Sound -> Sound -> Output palette. That link is the 2011 documentation (couldn't find a more recent link), but it does not look like it has changed. The working result is shown below, with two different events handled by the event structure:
Key Down? event:
Stop Button event:
You may be fine without using the Sound Output Clear VI to the right of the main event loop, but having it there won't hurt.
It turns out that the Play Sound File VI does not block, so you can play multiple overlapping sound files. If you run into blocking on your machine (one sound file plays, then the next, and so on), let me know because I have another solution that might work.
A word on events
An important thing to understand is that events are handled in a queue. When you press keys, those key presses go in order onto the event queue. Each time your event-handling loop executes, it takes the oldest event out of that queue and processes it. The event structure in LabVIEW will only handle one event per iteration of your event-handling loop. On the next iteration, if events are still in the queue that your structure is set up to process, it will take the next-oldest one for that iteration and repeat.
Now, lets say that you want to do some super complicated processing that takes 10 seconds every time you press a key, and you put that processing inside of your main event loop. Your key presses still go onto the event queue as fast as you press them, but LabVIEW has to wait the full 10 seconds before it can dequeue the next keypress and process it, so you end up with an application that seems to hang while it chugs through the queue much slower than you are adding items to the queue.
One way to get around this is to take that complicated processing and put it outside of the queue in another process. If you have the resources, you can actually call a separate instance of a processing sub-VI in its own thread for every one of those key presses. This allows the event handling loop to spawn processes as fast as you can press keys, and then your processes take whatever time they need to simultaneously (resources permitting) perform whatever actions you wanted.
Essentially that is what the Play Sound File VI is doing. It sees that you want to play a file and spawns a process to play that sound over the speakers, allowing the event-handling loop to continue immediately rather than waiting for the sound to finish playing. As you press more keys, more processes get spawn that kill themselves when they are finished. You can do this manually too, which is the other solution that I have for you if Play Sound File does not behave the same way for you as it did for me.
Update:
Thanks to #Engineero for pointing out that Play Sound File vi actually isn't blocking. The updated code shows how to play overlapping sounds. I'll leave it to the user to add the Stop Sound on Key Up code. No timeout is needed because nothing is taking place in the event structure.
Also, note that for me the Play Sound vi needed to be in a while loop to keep playing. Not sure why this is needed, but the NI examples sets it up this way (\examples\Graphics and Sound\Sound\Sound Player.vi).
Finally, you may crash the vi if your sound card gets overwhelmed as mentioned here. If that happens I would go with a better sound library to try and squeeze more performance out of your sound card.
Original:
First, I assume you a referring to this Launchpad?
I was able to press up to 4 keys at once will the following - the important thing is to set the event timeout to 1 ms. If you need more than that it will require a more sophisticated design.
I was no able to easily implement a sound because all the basic LabVIEW beeps are what's considered "blocking I/O" meaning if you call 2 Beeps simultaneously than Windows will play one after another not both at the same time. You will need to implement you instrument notes using non blocking I/O probably in a language other than LabVIEW such as this C++ library.

Does the VideoCastManager support stopping of playback?

How do you go about stopping the playback of a video? I only see a method for pausing.
Can I maybe force the load of a null video or something like that?
There will be a version of CastCompanionLibrary that will be published soon which exposes stop and some more new features. In most cases, you don't really need to call stop since that unloads the video as well; you can simply pause. Are you dealing with live streams? What is your use case for calling stop?

How to play background sound (music) in GW-Basic

I am developing a game in GW-Basic.i want to add music to it but the problem is that i am unable to play in the background but when i add sound then first the sound is played then after that game execution is started and vICE vERSA .while i want that both things play at the same time..so any idea how to do it??
This is actually possible. Use the PLAY "MB" statement to enable "music background" mode. In this mode all PLAY notes and SOUNDs are queued and executed in the background while your program is running. You can queue up to 32 notes. Look up PLAY in this manual.

XAudio2, starting/stopping loops?

How can I start/stop audio looping in IXAudio2SourceVoice?
Basically it has a start/stop which starts and pauses the audio execution as well as an ExitLoop() function which stpos the audio once it has finished playing. What I'd like to do is call 'ExitLoop()' then at a later time restart the looping process. How can I do this?
It seems the only way that can be done is by submitting buffers to the source voice... was hopig there was a more simplistic way but apparently not so guess I'll just write a wrapper for it.
I think you can just call "IXAudio2SourceVoice->Stop(0);"
Pass a 0 as a parameter.

Resources