forked from anaqueila/GstMultimidia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reproduz.py
165 lines (125 loc) · 4.57 KB
/
reproduz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#Author: Ana Queila, Jeferson e Uesle
import sys, os
##### Importa a Biblioteca GTK+ #####
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
### Importa a Biblioteca Gstreamer ###
import pygst
pygst.require('0.10')
import gst
class Reproduz(object):
def on_open_activate(self, widget, data=None):
chooser = gtk.FileChooserDialog("Select file", self.janela, gtk.FILE_CHOOSER_ACTION_OPEN,\
( gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
filter = gtk.FileFilter()
filter.set_name("Video/Audio")
filter.add_mime_type("video/xvid")
filter.add_mime_type("video/divx")
filter.add_mime_type("video/mpeg")
filter.add_mime_type("video/rmvb")
filter.add_mime_type("video/flv")
filter.add_pattern("*.rmvb")
filter.add_pattern("*.flv")
filter.add_pattern("*.avi")
filter.add_pattern("*.divx")
filter.add_pattern("*.mpg")
filter.add_pattern("*.wmv")
filter.add_pattern("*.mpeg")
filter.add_pattern("*.mkv")
filter.add_pattern("*.ogg")
filter.add_pattern("*.mp4")
filter.add_pattern("*.wma")
filter.add_pattern("*.mp3")
filter.add_pattern("*.flac")
filter.add_pattern("*.wav")
filter.add_pattern("*.aac")
filter.add_pattern("*.aiff")
chooser.add_filter(filter)
response = chooser.run()
if response == gtk.RESPONSE_OK:
self.currentFile= chooser.get_filename()
self.on_play()
chooser.destroy()
def on_play_clicked(self, widget, data=None):
if self.player.get_state()[1] == gst.STATE_NULL:
filepath = self.currentFile
if os.path.isfile(filepath):
self.player.set_property("uri", "file://" + filepath)
self.player.set_state(gst.STATE_PLAYING)
elif self.player.get_state()[1] == gst.STATE_PAUSED:
self.player.set_state(gst.STATE_PLAYING)
def on_pause_clicked(self, widget, data=None):
if self.player.get_state()[1] == gst.STATE_PLAYING:
self.player.set_state(gst.STATE_PAUSED)
def on_stop_clicked(self, widget, data=None):
if self.player.get_state()[1] == gst.STATE_PLAYING:
self.player.set_state(gst.STATE_NULL)
elif self.player.get_state()[1] == gst.STATE_PAUSED:
self.player.set_state(gst.STATE_NULL)
def on_volume_value_changed(self, widget, vol):
self.player.set_property("volume", float(vol))
def on_quit_activate(self, widget, data=None):
self.janela.hide()
gtk.main_quit()
def on_janela_destroy(self, widget, data=None):
self.player.set_state(gst.STATE_NULL)
arquivoglade = "Reproduz.glade"
def __init__ (self):
self.imagesink = None
#Instancia a classe Builder
builder = gtk.Builder()
#Carregando o Arquivo glade
builder.add_from_file(self.__class__.arquivoglade)
#carregando janela
self.janela = builder.get_object("janela")
self.movie_window = builder.get_object("movie_window")
self.volume = builder.get_object("volume")
#conectando os sinais
builder.connect_signals(self)
self.janela.show_all()
self.movie_window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(red=0, green=0, blue=0, pixel=65535))
self.player = gst.element_factory_make("playbin", "src")
sink = gst.element_factory_make("xvimagesink", "video-output")
asink = gst.element_factory_make("osssink", "audio-output")
self.player.set_property("video-sink", sink)
self.player.set_property("audio-sink", asink)
self.player.props.vis_plugin = gst.element_factory_make ("goom2k1")
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
bus.connect("sync-message::element", self.on_sync_message)
gtk.gdk.threads_init()
gtk.main()
def on_play(self):
if self.player.get_state()[1] == gst.STATE_NULL:
filepath = self.currentFile
if os.path.isfile(filepath):
self.player.set_property("uri", "file://" + filepath)
self.player.set_state(gst.STATE_PLAYING)
elif self.player.get_state()[1] == gst.STATE_PAUSED:
self.player.set_state(gst.STATE_PLAYING)
def on_message(self, bus, message):
t = message.type
print t
if t == gst.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
elif t == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.player.set_state(gst.STATE_NULL)
def on_sync_message(self, bus, message):
if message.structure is None:
return False
message_name = message.structure.get_name()
if message_name == "prepare-xwindow-id":
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
gtk.gdk.threads_enter()
imagesink.set_xwindow_id(self.movie_window.window.xid)
gtk.gdk.threads_leave()