Audio stream (shoutcast) playback - quick trick (Windows)

Share your advanced PureBasic knowledge/code with the community.
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Audio stream (shoutcast) playback - quick trick (Windows)

Post by firace »

Code: Select all

H$ + "<meta http-equiv='X-UA-Compatible' content='IE=edge' />" 
H$ + "<body bgcolor=black scroll=no><audio autoplay controls>"
H$ + "<source src='http://176.9.219.133:9998/stream'></audio>"

OpenWindow(0, 88, 244, 400, 140, "") : SetWindowColor(0,0)
WebGadget (0, 150, 000, 85,  80, "")
SetGadgetItemText(0, 1, H$)

Repeat : Until WaitWindowEvent() = 13116
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Audio stream (shoutcast) playback - quick trick (Windows

Post by Marc56us »

:shock:
Excellent !

I will (perhaps) adopt it for my software: exit the need of a DLL to play shoutcast.
Just need to find a way to adjust the volume without changing the overall volume. :?:

Thanks for this trick

8)
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Audio stream (shoutcast) playback - quick trick (Windows

Post by falsam »

Thank for sharing.

I added two buttons to adjust the volume (step 0.1) and three radios
The initial volume set at 50%

Code: Select all

Enumeration window
  #mainForm
EndEnumeration

Enumeration gadget
  #audio
  #stream
EndEnumeration

Declare loadStream()
Declare selectStream()

Global stream.s, HTML.s

OpenWindow(#mainForm, 88, 244, 190, 160, "Web Radio", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
SetWindowColor(#mainForm, RGB(0, 0, 0))
WebGadget (#audio, 0, 0, 170, 137, "")
ComboBoxGadget(#stream, 0, 137, 190, 23)

BindGadgetEvent(#stream, @selectStream(), #PB_EventType_Change)

loadStream()
SetGadgetState(#stream, 0)
selectStream()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Procedure loadStream()
  Restore stream
  
  For i = 0 To 3
    Read.s title$
    Read.s stream$
    AddGadgetItem(#stream, -1, title$)
    SetGadgetItemData(#stream, i, i)
  Next
EndProcedure

Procedure selectStream()
  Protected index = GetGadgetItemData(#stream, GetGadgetState(#stream)), n
  
  Restore stream
  For n = 0 To index
    Read.s title$
    Read.s stream$
  Next
  
  stream = stream$
  
  ;HTML
  HTML = "<meta http-equiv='X-UA-Compatible' content='IE=edge' />" 
  HTML + "<body bgcolor=black scroll=no>"
  HTML + "<audio id = 'stream' autoplay controls>"
  HTML + "<source src='" + stream + "'>"
  HTML + "</audio>"
  HTML + "<p style='padding-left: 40px'>"
  HTML + "<button onclick='subtractVolume()' type='button' style= 'width: 50px; height: 24px' title='Volume -0.1'>-</button>"
  HTML + "<button onclick='addVolume()' type='button' style= 'width: 50px; height: 24px' title='Volume +0.1'>+</button>"
  HTML + "</p>"
  
  ;Script
  HTML + "<script>"
  HTML + "var audio = document.getElementById('stream');"
  HTML + "audio.volume = 0.5;"
  HTML + "function addVolume() { if (audio.volume + 0.1 < 1.0) { audio.volume += 0.1;} }"
  HTML + "function subtractVolume() { if (audio.volume - 0.1 > 0) { audio.volume -= 0.1;} }"
  HTML + "</script>"
  
  SetGadgetItemText(#audio, #PB_Web_HtmlCode , HTML)
EndProcedure

DataSection
  stream:
  Data.s "Deep link NYC", "http://176.9.219.133:9998/stream"
  Data.s "DI Radio", "http://5.39.71.159:8110/stream"
  Data.s "Club hits", "http://178.32.62.172:9371/stream"
  Data.s "Creek Valley Radio", "http://192.99.34.205:8356/stream"
EndDataSection
Last edited by falsam on Mon Aug 15, 2016 1:34 am, edited 2 times in total.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Audio stream (shoutcast) playback - quick trick (Windows

Post by Derren »

Cool. If it'sjust an html5 audio element, you can find lots of code to add controls, like a real volume slider using JS and CSS online.
thanks for posting.
Nice stream as well ;)
Post Reply