Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #############################################################################
  4. ##
  5. ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
  6. ## Contact: Qt Software Information (qt-info@nokia.com)
  7. ##
  8. ## This file is part of the example classes of the Qt Toolkit.
  9. ##
  10. #############################################################################
  11.  
  12. from PySide import QtCore, QtGui
  13. import os
  14. import gst
  15.  
  16. class Player(QtGui.QWidget):
  17. def __init__(self, parent=None):
  18. super(Player, self).__init__(parent)
  19. self.playing = False
  20.  
  21. self.addButton = QtGui.QPushButton("Play")
  22. self.addButton.show()
  23.  
  24. self.addButton.clicked.connect(self.start_stop)
  25.  
  26. buttonLayout1 = QtGui.QVBoxLayout()
  27. buttonLayout1.addWidget(self.addButton, QtCore.Qt.AlignTop)
  28. buttonLayout1.addStretch()
  29.  
  30. mainLayout = QtGui.QGridLayout()
  31. mainLayout.addLayout(buttonLayout1, 1, 2)
  32.  
  33. self.setLayout(mainLayout)
  34. self.setWindowTitle("BeatTone Recorder")
  35.  
  36. #Load the gstreamer playing system
  37. self.gst_player = gst.element_factory_make("playbin", "player")
  38. fakesink = gst.element_factory_make("fakesink", "fakesink")
  39. self.gst_player.set_property("video-sink", fakesink)
  40. bus = self.gst_player.get_bus()
  41. bus.add_signal_watch()
  42. bus.connect("message", self.on_message)
  43.  
  44. def on_message(self, bus, message):
  45. '''
  46. Report an error if it happens.
  47. TODO: Do I need this or does it need to be done differently?
  48. '''
  49. #print bus
  50. t = message.type
  51. if t == gst.MESSAGE_EOS:
  52. self.gst_player.set_state(gst.STATE_NULL)
  53. elif t == gst.MESSAGE_ERROR:
  54. self.gst_player.set_state(gst.STATE_NULL)
  55. err, debug = message.parse_error()
  56. print "Error: %s" % err, debug
  57.  
  58. def start_stop(self):
  59. #Start and stop the player
  60. if self.playing:
  61. self.addButton.setText("Play")
  62. self.playing = False
  63. print "Stopping and saving.."
  64. self.gst_player.set_state(gst.STATE_NULL)
  65. self.button.set_label("gtk-media-play")
  66. #Take the data that has been recorded in this track and save it to the list of tracks with there dictionaries
  67. print self.keyHits
  68. self.recordingTrack[self.currentTrack] = self.keyHits
  69. self.keyHits.clear()
  70. self.beatHits = 0
  71. else:
  72. self.addButton.setText("Stop")
  73. self.playing = True
  74. print "Loading and Playing"
  75. self.gst_player.set_property("uri", "file://home/encompass/song.mp3")
  76. self.gst_player.set_state(gst.STATE_PLAYING)
  77.  
  78. if __name__ == '__main__':
  79. import sys
  80.  
  81. app = QtGui.QApplication(sys.argv)
  82. player = Player()
  83. player.show()
  84. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement