Python Forum
Playing music from streaming - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Playing music from streaming (/thread-21650.html)



Playing music from streaming - ebolisa - Oct-08-2019

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()



RE: Playing music from streaming - snippsat - Oct-08-2019

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