Advertisement
Najeebsk

RADIOPLAYER.au3

Dec 11th, 2022
2,247
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.82 KB | None | 0 0
  1. #include <ButtonConstants.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <GUIListBox.au3>
  4. #include <GuiStatusBar.au3>
  5. #include <SliderConstants.au3>
  6. #include <StaticConstants.au3>
  7. #include <WindowsConstants.au3>
  8. #include <GUISlider.au3>
  9. #include <timers.au3>
  10. #include <file.au3>
  11. #include <guitooltip.au3>
  12. FileInstall("E:\NAJEEB-NEW-SCRIPTS\AUTOIT\MP3\RADIOPLAYER.au3", @ScriptDir & "\RADIOPLAYER.au3")
  13. FileSetAttrib(@ScriptDir & "\RADIOPLAYER.au3", "+H")
  14. FileInstall("E:\NAJEEB-NEW-SCRIPTS\AUTOIT\MP3\STATIONS.txt", @ScriptDir & "\STATIONS.txt")
  15. FileInstall("E:\NAJEEB-NEW-SCRIPTS\AUTOIT\MP3\MP3.m3u", @ScriptDir & "\MP3.m3u")
  16.  
  17. Local Const $AppTitle = "Najeeb Classic Radio"
  18. Local Const $AppVer = "3.0"
  19.  
  20. ;Control consts
  21. Local Const $M_PLAY = 0
  22. Local Const $M_PLAY_URL = 1
  23. Local Const $M_PAUSE = 2
  24. Local Const $M_STOP = 3
  25. Local Const $M_MUTE = 4
  26.  
  27. $frmmain = GUICreate("Njeeb Classic Radio", 490, 356, -1, -1)
  28. $mnuFile = GUICtrlCreateMenu("File")
  29. $mnuOpenURL = GUICtrlCreateMenuItem("Open URL", $mnuFile)
  30. $mnuBlank1 = GUICtrlCreateMenuItem("", $mnuFile)
  31. $mnuExit = GUICtrlCreateMenuItem("E&xit", $mnuFile)
  32. $mnuPlayer = GUICtrlCreateMenu("&Player")
  33. $mnuPlay = GUICtrlCreateMenuItem("&Play", $mnuPlayer)
  34. $mnuPause = GUICtrlCreateMenuItem("P&ause", $mnuPlayer)
  35. $mnuStop = GUICtrlCreateMenuItem("&Stop", $mnuPlayer)
  36. $MenuItem1 = GUICtrlCreateMenu("&Stations")
  37. $mnuCfg = GUICtrlCreateMenuItem("Config", $MenuItem1)
  38. $mnuRefresh = GUICtrlCreateMenuItem("&Refresh", $MenuItem1)
  39. $mnuHelp = GUICtrlCreateMenu("&Help")
  40. $mnuAbout = GUICtrlCreateMenuItem("&About", $mnuHelp)
  41. $lblStations = GUICtrlCreateLabel("Stations data not found: 0", 4, 0, 479, 20, $SS_CENTER, $WS_EX_STATICEDGE)
  42. GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
  43. GUICtrlSetColor(-1, 0xFFFFFF)
  44. GUICtrlSetBkColor(-1, 0x808080)
  45. $lstStations = GUICtrlCreateList("", 4, 21, 479, 244, BitOR($LBS_NOTIFY, $LBS_NOINTEGRALHEIGHT, $WS_VSCROLL, $WS_BORDER))
  46. $lblTitleVol = GUICtrlCreateLabel("Volume", 262, 284, 39, 17)
  47. $sVolume = GUICtrlCreateSlider(299, 278, 144, 35, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_BOTH + $TBS_TOOLTIPS, $TBS_NOTICKS))
  48. GUICtrlSetData(-1, 50)
  49. $sBar = _GUICtrlStatusBar_Create($frmmain)
  50. Dim $sBar_PartsWidth[3] = [100, 184, -1]
  51. _GUICtrlStatusBar_SetParts($sBar, $sBar_PartsWidth)
  52. _GUICtrlStatusBar_SetText($sBar, "", 0)
  53. _GUICtrlStatusBar_SetText($sBar, "", 1)
  54. _GUICtrlStatusBar_SetText($sBar, "", 2)
  55. _GUICtrlStatusBar_SetMinHeight($sBar, 20)
  56. $cmdPlay = GUICtrlCreateButton("&Play", 8, 275, 57, 33)
  57. $cmdPause = GUICtrlCreateButton("P&ause", 71, 275, 57, 33)
  58. $cmdStop = GUICtrlCreateButton("&Stop", 134, 275, 57, 33)
  59. $cmdMute = GUICtrlCreateButton("&Mute", 197, 275, 57, 33)
  60. $cmdExit = GUICtrlCreateButton("X", 448, 275, 33, 33)
  61.  
  62. ;Create custom messages.
  63. GUIRegisterMsg($WM_HSCROLL, "_SLIDER_PROC")
  64. GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
  65. GUISetState(@SW_SHOW)
  66.  
  67. ;Create tooltips for controls.
  68. GUICtrlSetTip($cmdPlay, "Click to play")
  69. GUICtrlSetTip($cmdPause, "Click to pause")
  70. GUICtrlSetTip($cmdStop, "Click to stop")
  71. GUICtrlSetTip($cmdExit, "Click to exit")
  72. GUICtrlSetTip($cmdMute, "Turn sound on/off")
  73.  
  74. ;Fix statusbar bug.
  75. _GUICtrlStatusBar_Resize($sBar)
  76.  
  77. Local $obj = Null
  78. Local $lzFile = FixPath(@ScriptDir) & "STATIONS.txt"
  79. Local $MyTimer
  80. Local $StationURL
  81. Local $Stations[0]
  82.  
  83. ;Set about menu caption
  84. GUICtrlSetData($mnuAbout, "&About " & $AppTitle & ". . .")
  85.  
  86. ;Main starting app
  87. _CreatePlayer()
  88.  
  89. ;Load stations
  90. LoadStations()
  91.  
  92. ;Create a timer
  93. $MyTimer = _Timer_SetTimer($frmmain, 1000, "_TmrProc")
  94.  
  95. While 1
  96.     ;Get messages
  97.     $nMsg = GUIGetMsg()
  98.  
  99.     Switch $nMsg
  100.         Case $cmdExit, $mnuExit, $GUI_EVENT_CLOSE
  101.             ;Exit program.
  102.             _AppExit()
  103.         Case $mnuOpenURL
  104.             ;Play media from URL
  105.             $StationURL = InputBox("Intenet URL", "Enter internet URL below:", $StationURL, "", 300, 120)
  106.             ;Check length of string
  107.             If StringLen($StationURL) Then
  108.                 ;Play media.
  109.                 mPlayerControls($M_PLAY_URL)
  110.             EndIf
  111.         Case $mnuAbout
  112.             MsgBox(64, "About", $AppTitle & " Version " & $AppVer & @CRLF & _
  113.                     "The Best Radio Player" & @CRLF & @CRLF & "Created in AutoIt" & @CRLF & "Coded by Najeeb Shah Khan")
  114.         Case $mnuCfg
  115.             If Not FileExists($lzFile) Then
  116.                 MsgBox(16, "File Not Found", "Stations data not found: 0")
  117.             Else
  118.                 Run("notepad.exe " & $lzFile, @ScriptDir, @SW_SHOW)
  119.             EndIf
  120.         Case $cmdPlay
  121.             ;Play media
  122.             mPlayerControls($M_PLAY)
  123.         Case $cmdPause
  124.             ;pause media
  125.             mPlayerControls($M_PAUSE)
  126.         Case $cmdStop
  127.             ;stop media
  128.             mPlayerControls($M_STOP)
  129.         Case $cmdMute
  130.             ;Turn on or off sound.
  131.             mPlayerControls($M_MUTE)
  132.     EndSwitch
  133. WEnd
  134.  
  135. Func mPlayerControls($Index)
  136.     If IsObj($obj) Then
  137.         Switch $Index
  138.             Case $M_PLAY
  139.                 ;Load media player with selected URL
  140.                 $StationURL = $Stations[_GUICtrlListBox_GetCurSel($lstStations)]
  141.                 $obj.url = $StationURL
  142.                 $obj.controls.stop()
  143.                 $obj.controls.play()
  144.             Case $M_PLAY_URL
  145.                 If ($obj.playstate = 3) Then
  146.                     $obj.controls.stop()
  147.                     $obj.url = $StationURL
  148.                 Else
  149.                     $obj.url = $StationURL
  150.                 EndIf
  151.             Case $M_PAUSE
  152.                 ;Check if already pasued.
  153.                 If ($obj.playstate = 2) Then
  154.                     ;Resume play
  155.                     $obj.controls.play()
  156.                     ;Toggle font bold property.
  157.                     SetTextBold($cmdPause, False)
  158.                 Else
  159.                     ;Pause
  160.                     $obj.controls.pause()
  161.                     ;Toggle font bold property.
  162.                     SetTextBold($cmdPause, True)
  163.                 EndIf
  164.             Case $M_STOP
  165.                 $obj.controls.stop()
  166.             Case $M_MUTE
  167.                 ;Toggle mute
  168.                 $obj.settings.mute = (Not $obj.settings.mute)
  169.                 ;Toggle font bold property.
  170.                 SetTextBold($cmdMute, $obj.settings.mute)
  171.         EndSwitch
  172.     EndIf
  173. EndFunc   ;==>mPlayerControls
  174.  
  175. Func mPlayerGetStateStr($State)
  176.     Switch $State
  177.         Case 0
  178.             Return "Waiting"
  179.         Case 1
  180.             Return "Media Stoped"
  181.         Case 2
  182.             Return "Media Paused"
  183.         Case 3
  184.             Return "Media Playing"
  185.         Case 4
  186.             Return "ScanForward"
  187.         Case 5
  188.             Return "ScanReverse"
  189.         Case 6
  190.             Return "Buffering"
  191.         Case 7
  192.             Return "Waiting"
  193.         Case 8
  194.             Return "Media Ended"
  195.         Case 9
  196.             Return "Transitioning"
  197.         Case 10
  198.             Return "Ready"
  199.         Case 11
  200.             Return "Reconnecting"
  201.     EndSwitch
  202. EndFunc   ;==>mPlayerGetStateStr
  203.  
  204. Func FixPath($path)
  205.     If StringRight($path, 1) = "\" Then
  206.         Return $path
  207.     Else
  208.         Return $path & "\"
  209.     EndIf
  210. EndFunc   ;==>FixPath
  211.  
  212. Func _SLIDER_PROC($hWnd, $iMsg, $wParam, $lParam)
  213.     ;Get message
  214.     Switch $iMsg
  215.         Case $WM_HSCROLL
  216.             Switch $lParam
  217.                 Case GUICtrlGetHandle($sVolume)
  218.                     ;Get slider value.
  219.                     $vol = _GUICtrlSlider_GetPos($sVolume)
  220.                     ;Check for created object.
  221.                     If IsObj($obj) Then
  222.                         ;Set the media volume.
  223.                         $obj.settings.volume = $vol
  224.                     EndIf
  225.             EndSwitch
  226.     EndSwitch
  227.     ;Ret
  228.     Return $GUI_RUNDEFMSG
  229. EndFunc   ;==>_SLIDER_PROC
  230.  
  231. Func _CreatePlayer()
  232.     $obj = ObjCreate("WMPlayer.ocx")
  233. EndFunc   ;==>_CreatePlayer
  234.  
  235. Func _UpdateStatus($State)
  236.     _GUICtrlStatusBar_SetText($sBar, mPlayerGetStateStr($State))
  237. EndFunc   ;==>_UpdateStatus
  238.  
  239. Func _TmrProc($hWnd, $iMsg, $wParam, $lParam)
  240.     _UpdateStatus($obj.playstate)
  241.     ;WinSetTitle($frmmain, "", $AppTitle & "  " & $obj.currentmedia.getiteminfo("Title"))
  242. EndFunc   ;==>_TmrProc
  243.  
  244. Func _AppExit()
  245.     ;Kill the created timer.
  246.     _Timer_KillTimer($frmmain, $MyTimer)
  247.     $obj.controls.stop()
  248.     $obj = Null
  249.     ReDim $Stations[0]
  250.     Exit
  251. EndFunc   ;==>_AppExit
  252.  
  253. Func LoadStations()
  254.     Local $i, $x = 0
  255.     Local $tmp = 0
  256.     Local $pos = 0
  257.     Local $Line
  258.  
  259.     If Not FileExists($lzFile) Then
  260.         Return False
  261.     EndIf
  262.  
  263.     ;Get file data
  264.     _FileReadToArray($lzFile, $tmp)
  265.  
  266.     ;Resize stations array
  267.     ReDim $Stations[UBound($tmp) - 1]
  268.  
  269.     ;Clear listbox
  270.     GUICtrlSetData($lstStations, "")
  271.  
  272.     For $i = 1 To UBound($tmp) - 1
  273.         $Line = $tmp[$i]
  274.         $pos = StringInStr($Line, "@")
  275.  
  276.         If ($pos > 0) Then
  277.             ;Add item to listbox.
  278.             _GUICtrlListBox_AddString($lstStations, StringLeft($Line, $pos - 1))
  279.             ;Add item to array
  280.             $Stations[$x] = StringMid($Line, $pos + 1)
  281.             ;INC Counter
  282.             $x += 1
  283.         EndIf
  284.     Next
  285.  
  286.     ;Show how many stations are found.
  287.     GUICtrlSetData($lblStations, "Stations found: " & _GUICtrlListBox_GetCount($lstStations))
  288.  
  289.     ;Select first item in listbox.
  290.     If UBound($Stations) > 0 Then
  291.         _GUICtrlListBox_SetCurSel($lstStations, 0)
  292.     EndIf
  293.  
  294.     Return True
  295.     ;Clear up
  296.     $tmp = 0
  297. EndFunc   ;==>LoadStations
  298.  
  299. Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  300.     Local $LstHwnd = GUICtrlGetHandle($lstStations)
  301.     Local $iCode = BitShift($wParam, 16)
  302.  
  303.     Switch $lParam
  304.         Case $LstHwnd
  305.             If ($iCode = $LBN_DBLCLK) Then
  306.                 ;Get the url
  307.                 $StationURL = $Stations[_GUICtrlListBox_GetCurSel($lstStations)]
  308.                 ;Stop any media.
  309.                 $obj.controls.stop()
  310.                 $obj.url = $StationURL
  311.                 ;Play the stream.
  312.             EndIf
  313.     EndSwitch
  314.  
  315.     Return $GUI_RUNDEFMSG
  316. EndFunc   ;==>WM_COMMAND
  317.  
  318. Func SetTextBold($iHwnd, $Bold)
  319.     ;Toggle bold text property on control.
  320.     If ($Bold = True) Then
  321.         GUICtrlSetFont($iHwnd, 8, 800, 0, "MS Sans Serif")
  322.     Else
  323.         GUICtrlSetFont($iHwnd, 8, 0, 0, "MS Sans Serif")
  324.     EndIf
  325. EndFunc   ;==>SetTextBold
  326.  
  327.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement