Python Forum
Playing music from streaming
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Playing music from streaming
#1
Hi,

I use the code below to play mp3 files but, how do I play a streaming site like this one: http://icy-4.radioparadise.com/aac-128

TIA


#!/usr/bin/python3

from __future__ import print_function
import logging
import pygame

logging.basicConfig(filename='/home/pi/proj/musicfile.log',level=logging.DEBUG)

#music files path
song = "music.mp3"

pygame.init()
pygame.mixer.init()

def play_song():
   try:
       #pygame.mixer.music.set_volume(0.50)
       pygame.mixer.music.load(song)
       pygame.mixer.music.play()
       clock = pygame.time.Clock()
       clock.tick(10)
       while pygame.mixer.music.get_busy():
           pygame.time.Clock().tick(10)
   except Exception as e:
        logging.exception("msg from music.py " + str(e))
        # Logs the error appropriately.
        raise

if __name__ == '__main__':
    while True:
        play_song()
Reply
#2
I would just call ffplay a part of FFmpeg.
This works.
import subprocess

stream = 'http://icy-4.radioparadise.com/aac-128'
subprocess.run(['ffplay', stream])
Libraries pydub, python-vlc, ffmpeg-python
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to decrease latency while recording streaming video. unicorn2019 0 1,232 Nov-15-2021, 02:12 PM
Last Post: unicorn2019
  Python 3.5 streaming output to the same log file that I write to cbj0517 2 2,708 Apr-23-2019, 04:38 PM
Last Post: cbj0517
  Streaming to website instead of Window OpenCV SDGRIFFUSW 1 1,893 Apr-19-2019, 09:59 PM
Last Post: SheeppOSU
  Python and SQL BLOB Streaming ashtona 4 4,325 May-09-2018, 06:13 PM
Last Post: ashtona
  Video Streaming Python 3 adaptation failling maimonid 8 8,478 Dec-28-2016, 09:20 AM
Last Post: maimonid

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020