fix playback issue (#20)

This commit is contained in:
Olaf Leidinger 2015-02-22 11:18:16 +01:00
parent 5153e81064
commit 73f394bc2a

View File

@ -84,10 +84,24 @@ function formatTime(sec_num) {
} }
function playSound(uri) { function playSound(uri) {
Gst.init(null, 0); if ( typeof this.player == 'undefined' ) {
let player = Gst.ElementFactory.make("playbin","player"); Gst.init(null, 0);
player.set_property('uri', uri); this.player = Gst.ElementFactory.make("playbin","player");
player.set_state(Gst.State.PLAYING); this.playBus = this.player.get_bus();
this.playBus.add_signal_watch();
this.playBus.connect("message", Lang.bind(this,
function(playBus, message) {
if (message != null) {
// IMPORTANT: to reuse the player, set state to READY
let t = message.type;
if ( t == Gst.MessageType.EOS || t == Gst.MessageType.ERROR) {
this.player.set_state(Gst.State.READY);
}
} // message handler
}));
} // if undefined
this.player.set_property('uri', uri);
this.player.set_state(Gst.State.PLAYING);
} }
function setCairoColorFromClutter(cr, c) { function setCairoColorFromClutter(cr, c) {