Python Forum

Full Version: Playing music from streaming
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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