Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #############################################################################
- ##
- ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
- ## Contact: Qt Software Information (qt-info@nokia.com)
- ##
- ## This file is part of the example classes of the Qt Toolkit.
- ##
- #############################################################################
- from PySide import QtCore, QtGui
- import os
- import gst
- class Player(QtGui.QWidget):
- def __init__(self, parent=None):
- super(Player, self).__init__(parent)
- self.playing = False
- self.addButton = QtGui.QPushButton("Play")
- self.addButton.show()
- self.addButton.clicked.connect(self.start_stop)
- buttonLayout1 = QtGui.QVBoxLayout()
- buttonLayout1.addWidget(self.addButton, QtCore.Qt.AlignTop)
- buttonLayout1.addStretch()
- mainLayout = QtGui.QGridLayout()
- mainLayout.addLayout(buttonLayout1, 1, 2)
- self.setLayout(mainLayout)
- self.setWindowTitle("BeatTone Recorder")
- #Load the gstreamer playing system
- self.gst_player = gst.element_factory_make("playbin", "player")
- fakesink = gst.element_factory_make("fakesink", "fakesink")
- self.gst_player.set_property("video-sink", fakesink)
- bus = self.gst_player.get_bus()
- bus.add_signal_watch()
- bus.connect("message", self.on_message)
- def on_message(self, bus, message):
- '''
- Report an error if it happens.
- TODO: Do I need this or does it need to be done differently?
- '''
- #print bus
- t = message.type
- if t == gst.MESSAGE_EOS:
- self.gst_player.set_state(gst.STATE_NULL)
- elif t == gst.MESSAGE_ERROR:
- self.gst_player.set_state(gst.STATE_NULL)
- err, debug = message.parse_error()
- print "Error: %s" % err, debug
- def start_stop(self):
- #Start and stop the player
- if self.playing:
- self.addButton.setText("Play")
- self.playing = False
- print "Stopping and saving.."
- self.gst_player.set_state(gst.STATE_NULL)
- self.button.set_label("gtk-media-play")
- #Take the data that has been recorded in this track and save it to the list of tracks with there dictionaries
- print self.keyHits
- self.recordingTrack[self.currentTrack] = self.keyHits
- self.keyHits.clear()
- self.beatHits = 0
- else:
- self.addButton.setText("Stop")
- self.playing = True
- print "Loading and Playing"
- self.gst_player.set_property("uri", "file://home/encompass/song.mp3")
- self.gst_player.set_state(gst.STATE_PLAYING)
- if __name__ == '__main__':
- import sys
- app = QtGui.QApplication(sys.argv)
- player = Player()
- player.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement