sound.PlayURL - YouTube Links ?

Hey!

I would like to play YouTube Links with the sound.PlayURL function,
so I created a converter or basically I just used the youtube-dl API.
In fact the converting works and it outputs the file, I cannot play it ingame.

Well… I tried to play the converted manually and it gives me an Bass error: BASS_ERROR_UNKNOWN

I can play this file in the browser and locally on my pc but when I use it ingame it doesnt work.

Has anyone an idea why ?

can you atleast show us what link are you trying to reproduce? There are hundreds of threads about playing youtube songs inside gmod that you can check

You should know that BASS usually does not support video files. If you haven’t yet you should convert them to mp3 first.

If you want to play a local file, it has to be inside the garrysmod folder and you have to use sound.PlayFile().

Do not forget to add the protocol (“http://”, “https://”, “ftp://”, etc.) to the URL if you want to stream from a network/online resource.

Can be so?


YouTube("0JklSDqoUOU")
function YouTube(id)
	local url = string.format("https://www.youtube.com/embed/%s/?rel=0&autoplay=1&frameborder=0&autohide=1&controls=1", id)
	sound.PlayURL(url, "mono", function(station)
		if (IsValid(station)) then
			station:Play()
		else
			ServerLog("Invalid URL!")
		end
	end)
end

sound.PlayURL has to be a direct link (ogg, wav, mp3, etc.)

As I said I made an online converter using the youtube-dl libary. I converted it to .wav, .mp3 and .opus. None of these formats worked ingame even though I can play them in the browser and on the pc locally.
So basically I dont know why am I getting a bass error…

You are still not showing us the link and we won’t help you without those

https://www.xworld-rl.de/ytmp3/pBkHHoOIIn8.opus
Im trying to play this link

Do you think gmod can play an opus file? You kept ignoring our comments and trying to make stuff work while everyone here told you that you can only play wav, ogg and mp3 files…

Most of convertors won’t ever work since it’s an asynchronous process to convert, and i’m most likely sure that you’re not handling the convertion correctly, having youtube as music player is a pretty bad idea actually, just because it’s way hard to get it working without understanding how gmod works and how youtube convertor works

I did a quick look at the youtube-dl API documentation and noticed that converting video is not that trivial, are you sure made the right settings for the converting?

I mean renaming a *.wav file to an *.mp3 one does not make it an actually *.mp3 file. The browser may be able to play it, but BASS is probably not that tolerant. I not assuming that you did it, I just want to point it out just in case as it is a common beginner mistake.

I didnt just remained the files, I did a complete new conversion with the right format flags and filename inclusively the Content-Type. Sadly it doenst work either…

Alright I downloaded the the given test file and tested it with BASS locally and also got the same error aswell. My guess that the file is either broken or BASS does not support the OPUS format.

I also tested the file with VLC Player and It played a load noise for a few seconds which is certainly not part of the song. Is this noise intended? If not your file is probably broken/corrupted and so unplayable by BASS. Unsupported formats also has an other error code than BASS_ERROR_UNKNOWN.

BASS_ERROR_UNKNOWN is usually mostly thrown on broken files and along with some other cases.

Dude…SHOW US WHAT ARE YOU TRYING…We are not going to steal your not working code, stop saying “doesn’t work” “i tried that” and such things that just tells us that you’re being lazy and doesn’t want to get stuff working without us giving you code that nobody has

You gave me a link, i told you that gmod doesn’t play opus even after you told us that you already tried other formats, but you still didn’t tell us how are you playing the sounds or corverting those

As i’ve say, you keep ignoring our comments, what are you trying to achieve, why are you taking our time like that

lol, what code do you need ?! I posted you my converter… Nothing more is needed.

Click the link: https://www.xworld-rl.de/ytmp3/?fetch=https://www.youtube.com/watch?v=pBkHHoOIIn8

A mp3 file will be created now with the youtube id as the name => pBkHHoOIIn8
.mp3

When the conversion is successfull you can get that link: https://www.xworld-rl.de/ytmp3/pBkHHoOIIn8.mp3

Afterwards you just need to play it ingame

sound.PlayURL(“https://www.xworld-rl.de/ytmp3/pBkHHoOIIn8.mp3”, “”, function(sMusic, iError, sError)
end);

I dont know what your problem is ?

I’ve entered inside the first page
Black screen with a music player control that can’t be played

It doesn’t redirects you inside that mp3 or either that mp3 file exists when you do the first query…Surprise!

That’s why it won’t work, just give it a time after you do the query and then try to play the sound after 5-20 seconds, it’s not reliable but should work after a time (In case converted file outputs a valid bitrate and source requirements)

Thats not the problem… Youtube-dl has async callbacks in PHP, so can redirect after it was converted, but for now I removed these lines to test it without… So first you need to convert the file as I said and afterwards you can visit the file in the browser manually, it will play the file.

If that is done test the file ingame, it doesnt work!

This thing has nothing to do with asynchronous process currently…

The given mp3 URL does not lead to a valid mp3 file. I looked into it: It seems to be a Webm file with an OPUS audio-codec.

Well, so thats the fault off youtube-dl Ive chosen the correct flags…