kibook / pmms

Synchronized media player for FiveM and RedM
136 stars 57 forks source link

Shoutcast / webmp3 support #4

Open Kurosar opened 3 years ago

Kurosar commented 3 years ago

Hello again,

Do you plan on adding support for shoutcast/icecast support ? Or the support to play a direct radio url ending with .mp3 (live)

Examples : http://yp.shoutcast.com/sbin/tunein-station.pls?id=1807142 http://yp.shoutcast.com/sbin/tunein-station.m3u?id=1807142

Best regards.

kibook commented 3 years ago

I think the "direct radio url ending with .mp3" should already work. Here's an example: http://rfcmedia.streamguys1.com/newpophits.mp3

There's a number of other factors that can cause a stream not to work. If you can provide a link to one that you were trying, I can try and take a look to see what the issue is.

pmms mainly uses the MediaElement.js library, so things which it does not support are less likely to be added. It does support HLS live streams with .m3u8 playlists, and MPEG-DASH, but I'm not sure about anything else. A quick test using MediaElement.js outside of pmms suggests it does not support those .pls and .m3u streams, though.

Kurosar commented 3 years ago

I'll have to try some more then, thanks !

Kurosar commented 3 years ago

Hey, in case you want to do some testing to maybe integrate shoutcast streams. Here's an url you can open on VLC (Ctrl + N) http://stream.friskyradio.com:8000

And here's what happens when I try to load it on pmms. image

DamonOnYT commented 3 years ago

Hey, in case you want to do some testing to maybe integrate shoutcast streams. Here's an url you can open on VLC (Ctrl + N) http://stream.friskyradio.com:8000

And here's what happens when I try to load it on pmms. image

The link there isn't a stream and has mp3 stream listening disabled

kibook commented 3 years ago

The link there isn't a stream and has mp3 stream listening disabled

The server actually sends different formats back depending on the User-Agent:

Standard cURL User-Agent:

$ curl -i --http0.9 http://stream.friskyradio.com:8000/

ICY 200 OK
icy-notice1:<BR>This stream requires <a href="http://www.winamp.com">Winamp</a><BR>
icy-notice2:SHOUTcast DNAS/posix(linux x64) v2.2.1.109<BR>
icy-name:FRISKY | feelin' frisky?
icy-genre:Electronic
icy-url:http://www.frisky.fm
content-type:audio/mpeg
icy-pub:1
icy-br:128

Typical web browser User-Agent:

curl -i --http0.9 -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0' http://stream.friskyradio.com:8000/

HTTP/1.1 302 Found
Content-Type:text/html;charset=utf-8
Location:/index.html
Content-Length:112

<html><head><title>Redirect</title></head><body>Click <a href="/index.html">here</a> for redirect.</body></html>

So some applications (like VLC) may receive back a non-standard HTTP response containing an MP3 stream, while your typical web browser will instead receive a redirect to a web page.

Since pmms is essentially operating inside a web browser (NUI/DUI use Chromium), that stream is probably redirecting to the web page when pmms requests it, instead of the direct MP3 stream.

That web page provides .pls playlists for the stream, which aren't directly supported by MediaElement.js and pmms, however, opening one of those .pls files reveals it is not a segmented playlist, but just a redirect to a single URL:

[playlist]
NumberOfEntries=1
File1=http://stream.friskyradio.com:8000/frisky_mp3_hi
Title1=FRISKY | feelin' frisky?
Length1=-1
Version=2

http://stream.friskyradio.com:8000/frisky_mp3_hi appears to be a consistent link to the direct MP3 stream. Unfortunately, it still doesn't appear to work with MediaElement.js and pmms, possibly because of the non-standard HTTP response format it uses.

kibook commented 3 years ago

I did a test with MediaElement.js outside of FiveM, and it worked, so despite the non-standard HTTP response, MediaElement.js can play it:

https://jsfiddle.net/kibukj/7pfrhwt5/

I think now the issue with pmms specifically is that the stream only supports plain HTTP and not HTTPS. The NUI/DUI browser does not appear to allow Mixed Content, which is when a secure page (like https://kibook.github.io/pmms, which is obviously served with HTTPS) requests insecure content. The web browser automatically tries to "upgrade" the request to HTTPS, but since that stream only supports plain HTTP, requesting it over HTTPS just results in a failed connection.

This error appears in the console before the errors printed by MediaElement.js and pmms:

Mixed Content: The page at 'https://kibook.github.io/pmms/?resourceName=pmms' was loaded over HTTPS, but requested an insecure element 'http://stream.friskyradio.com:8000/frisky_mp3_hi'. This request was automatically upgraded to HTTPS, For more information see https://blog.chromium.org/2019/10/no-more-mixed-messages-about-https.html (https://kibook.github.io/pmms/?resourceName=pmms:0)

One of the first working example streams in this issue, http://rfcmedia.streamguys1.com/newpophits.mp3, probably only works because it also supports HTTPS (https://rfcmedia.streamguys1.com/newpophits.mp3), so the web browser is able to upgrade the request behind the scenes.

A possible solution could be to detect the protocol the link uses, and use the same protocol to request the DUI page. Of course, this will not work with the default DUI server, as GitHub Pages only supports HTTPS, so it will only work if you provide a custom server that supports both.

kibook commented 2 years ago

297add6 switches pmms to use the HTTP server built in to FXServer for DUI instead of the external github.io page, which fixes the issue playing plain HTTP URLs.

Duderocktv commented 2 years ago

Hey!

So we are using a TuneIn compatible URL, from a radio station system: https://16963.live.streamtheworld.com/SAM05AAC326_SC

But the issue is that, even with loop set to false, it will play one song, and loop. Even though its a radio station :O.. It should just stream the content freely, if that makes sense? I tried setting loop to true and false but it still seems to repeat the songs for some reason!

kibook commented 2 years ago

When you play that link, does pmms display both a current timecode and duration (00:00:00/00:00:00) or only a current timecode (00:00:00)? If you only see a current timecode, it is correctly interpreting it as a live stream, but if you see both then pmms may be seeing it as a discrete audio file. It determines this usually based on whether the audio stream contains a set length/duration, but different sources have different conventions for reporting the duration so this doesn't always work correctly.

For audio streams determined to be live streams with no duration, the "loop" option is ignored and has no effect.

I haven't been able to replicate the issue in my own testing using the provided stream link. For me, pmms correctly interprets it as a live stream, and it doesn't "loop" the way you describe, but seems to play the live radio stream as expected.

Example display of an audio stream determined to have a set duration: FiveM_b2372_GTAProcess_aoxYlOfNyS

Example display of an audio stream that is determined to be a live stream with no duration: FiveM_b2372_GTAProcess_UoEU5j61YQ

Duderocktv commented 2 years ago

It was workinvg fine with with just 1 radio, and was working for a bit! But set up 10 of them and start moving from one location with a radio to another and youll see what I mean!

kibook commented 2 years ago

At that point it could be a connection issue with the stream. Having 10 instances of the same stream open is definitely not ideal.

Is the idea that you want it to play on many different radios around the map? I've been meaning to add some kind of option to play one stream on multiple objects for such a case. On my RedM server, I have a script that plays a stream of Christmas music on phonographs in saloons throughout the map, but I currently do not use pmms for this: https://github.com/kibook/redm-xmas. I rolled a custom system for it in order to only have one instance of the stream being "played on" multiple phonograph objects. I would like to eventually add this as an option in pmms.

Duderocktv commented 2 years ago

Yeah so basically we have a radio station with DJs. We want this same stream setup to at least 10 locations, synced up! I see your xmas one spawns the object as well. Would this work on gta?

kibook commented 2 years ago

It actually doesn't spawn the objects, that's done via my objectloader resource for RedM currently. The coordinates are just to know where to calculate the volume of the audio from. It's not as advanced as pmms as it doesn't determine whether the object is in the same interior room as the player, for example, but it gets the job done.

It would not work on FiveM as-is, but the method it uses (which is not much different from pmms) will work with some minor changes to the script, and removal of the other RedM-specific stuff. The basic idea is I have an NUI page that plays a single instance of the stream, and then the volume of the stream is calculated from your distance to the closest point in the list of points in phonographs.lua.

Duderocktv commented 2 years ago

Alright so I got it working!! the xmas thing! But if leave and come back, it doesnt start playing again!

image I saw this error pop up the one time but its not doing it again

If I restart the script and im standing in there: It works!!

Edit: 2. If I restart the script, or fresh boot, outside of the building, and walk in it, the music doesnt start :O

Edit 3: I was sitting there for a bit with the music through the redm-xmas and it does the same thing. I just takes a section of the radio, and just loops it. Its not even the full song. Only one radio going (only added one location)

I'm not too sure haha.