View Single Post
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#4
Originally Posted by ukaef View Post
This is the latest code of my work, before I abandon it. Someone already done what I was trying to do, so it was waste of time. Anyway, if you want to play mp3`s the key is to use gst module.

Code:
#!/usr/bin/python

import pygst
pygst.require("0.10")
import gst
import os
import pygtk
import gtk
import audioop

class Main:
	def __init__(self):
		self.pipeline = gst.Pipeline("mypipeline")
		self.audiotestsrc = gst.element_factory_make("alsasrc")
		self.pipeline.add(self.audiotestsrc)
		self.sink = gst.element_factory_make("appsink", "sink")
                self.sink.set_property('caps', gst.Caps('audio/x-raw-int, width=16, depth=16, signed=true'))
                self.sink.set_property('drop', False)
                self.sink.set_property('max-buffers', 5)
                self.sink.set_property('sync', False)
                #self.sink.connect('new-buffer', self._new_buffer)
                self.pipeline.add(self.sink)
                print('starting...')
		self.audiotestsrc.link(self.sink)
		self.pipeline.set_state(gst.STATE_PLAYING)
                # tmp = 0
                for i in range(1, 999999):
                    #new = ord(self.sink.emit('pull-buffer')[0])
                    # if new > tmp:
                    #os.system('clear') 
                    pipa = abs(audioop.avg(self.sink.emit('pull-buffer'), 2))
                    print(pipa*'x')
        #def _new_buffer(self, sink):
                #buf = sink.emit('pull-buffer')
                #print(buf)
start=Main()
gtk.main()
you can run this, its safe It will print "x" marks on console - as many as the sound output level from the pipeline.

Basically programming music app in python for n900 is about good understanding gstreamer pipelines. You should find example pipelines on google, then use this code to build your own pipeline to play mp3. In my code, source of sound is
Code:
self.audiotestsrc = gst.element_factory_make("alsasrc")
but gst have sources which will play mp3s.

good luck!
Thansk for your code! It is surprisingly involved. I'd have expected something like module.play(song).

Today I work with madplay or mplayer in a dirty way ("play" calls 'madplay <song>', "stop" kills the subprocess). The good point for me is the volume gain, that allows the N800 to play 15DB louder than max volume (to call birds).

I'll try to see if gst has volume gain.

Thanks!
L.