I have a Raspberry, with a simple lighttpd and python as CGI.
I try to play a MP3 to be played when I visit a web page.
So I can visit http://ip_rasp/play.py and the mp3 sounds with the Raspberry speaker.
The problem is that I think mixer is not initializing well when calling as web request:
The code is:
import pygame
import time
import os
pygame.init()
pygame.mixer.music.load("/var/www/ok.mp3")
pygame.mixer.music.play()
time.sleep(10)
It says:
/var/www/audio/play.py in ()
6
7 pygame.init()
=> 8 pygame.mixer.music.load("/var/www/ok.mp3")
9 pygame.mixer.music.play()
10 time.sleep(10)
pygame = <module 'pygame' from '/usr/lib/python2.7/dist-packages/pygame/__init__.pyc'>, pygame.mixer = <module 'pygame.mixer' from '/usr/lib/python2.7/dist-packages/pygame/mixer.so'>, pygame.mixer.music = <module 'pygame.mixer_music' from '/usr/lib/python2.7/dist-packages/pygame/mixer_music.so'>, pygame.mixer.music.load = <built-in function load>
<class 'pygame.error'>: mixer system not initialized
args = ('mixer system not initialized',)
message = 'mixer system not initialized'
If I run through raspberry console the command "python play.py" it works perfectly and I hear the MP3 with the speaker.
But I can not play with web request ...
Any idea or other solution ?
THANK YOU