×
Namespaces

Variants
Actions

How to create a mp3 player in Maemo

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Article
Created: User:Raulherbster (23 Sep 2008)
Last edited: hamishwillee (14 Jun 2013)

This source code shows how to create a simple mp3 player in Maemo platform.

#!/usr/bin/python
import pygst
pygst.require("0.10")
import gst
import pygtk
import gtk
import hildon
 
class Player(hildon.Program):
def __init__(self):
hildon.Program.__init__(self)
self.window = hildon.Window()
self.window.connect("delete_event", gtk.main_quit)
self.window.set_title("Player")
self.add_window(self.window)
 
self.create_interface()
self.create_pipeline()
 
self.window.add(self.table)
self.window.show_all()
 
def create_interface(self):
self.table = gtk.Table(2,2,True)
buttonPlay = gtk.Button("Play")
buttonPause = gtk.Button("Pause")
buttonStop = gtk.Button("Stop")
buttonOpen = gtk.Button("Open")
 
buttonPlay.connect("clicked",self.OnPlay)
buttonPause.connect("clicked",self.OnPause)
buttonStop.connect("clicked",self.OnStop)
buttonOpen.connect("clicked",self.OnOpen)
 
self.table.attach(buttonPlay,0,1,0,1)
self.table.attach(buttonPause,1,2,0,1)
self.table.attach(buttonStop,0,1,1,2)
self.table.attach(buttonOpen,1,2,1,2)
 
def create_pipeline(self):
# Create GStreamer bits and bobs
 
self.pipeline = gst.Pipeline("mypipeline")
 
self.audiosrc = gst.element_factory_make("gnomevfssrc","source")
self.pipeline.add(self.audiosrc)
 
self.audiosink = gst.element_factory_make("dspmp3sink", "sink")
self.pipeline.add(self.audiosink)
 
self.audiosrc.link(self.audiosink)
 
def OnPlay(self, widget):
self.pipeline.set_state(gst.STATE_PLAYING)
 
def OnPause(self, widget):
self.pipeline.set_state(gst.STATE_PAUSED)
 
def OnStop(self, widget):
if self.pipeline.get_state() != gst.STATE_PAUSED:
self.pipeline.set_state(gst.STATE_PAUSED)
if self.pipeline.get_state() != gst.STATE_NULL:
self.pipeline.set_state(gst.STATE_NULL)
 
def OnOpen(self, widget):
dialog = hildon.FileChooserDialog(self.window,gtk.FILE_CHOOSER_ACTION_OPEN)
response = dialog.run()
dialog.hide()
file_name = selector.get_filename()
if response == gtk.RESPONSE_OK:
self.audiosrc.set_property("location", file_name)
self.pipeline.set_state(gst.STATE_READY)
 
start=Player()
gtk.main()
This page was last modified on 14 June 2013, at 09:02.
50 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×