Namespaces
Variants
Actions

How to create a mp3 player in Maemo

Jump to: navigation, search
Article Metadata

Article
Created: User:Raulherbster (23 Sep 2008)
Last edited: hamishwillee (08 Feb 2012)

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

Comments

Reviewer-approved.png
15 Sep
2009
Article Review by nayan_trivedi (20090915)

This article is one of the simple article of Maemo applications in python.Code snippet shown in this article.This article contains multimedia in This application.

The simple player using python for Maemo is shown hear. Maemo multimedia applications - Part II


This article is very useful for the Maemo Multimedia developer.This may be useful for beginner of Meamo application developer.

This page was last modified on 8 February 2012, at 03:51.
80 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved