forked from anaqueila/GstMultimidia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
caudio.py
88 lines (62 loc) · 2.09 KB
/
caudio.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
# -*- 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 Caudio(object):
def on_record_clicked(self, widget, data=None):
if self.player.get_state()[1] == gst.STATE_NULL:
filepath = self.fcb.get_filename()
name = self.entry.get_text() + ".ogg"
if os.path.isdir(filepath):
self.sink.set_property("location", filepath + "/" + name)
self.player.set_state(gst.STATE_PLAYING)
def on_stop_clicked(self, widget, data=None):
if self.player.get_state()[1] == gst.STATE_PLAYING:
self.player.set_state(gst.STATE_NULL)
print "fim"
else:
print "nao tem fluxo"
def on_quit_clicked(self, widget, data=None):
self.janela.hide()
gtk.main_quit()
arquivoglade = "CapturaA.glade"
def __init__ (self):
builder = gtk.Builder()
builder.add_from_file(self.__class__.arquivoglade)
#carregando janela
self.janela = builder.get_object("janela")
self.fcb = builder.get_object("fcb")
self.entry = builder.get_object("entry")
builder.connect_signals(self)
self.janela.show_all()
self.player = gst.Pipeline("MyPlayer")
source = gst.element_factory_make("osssrc", "source")
convert = gst.element_factory_make("audioconvert",'audioconvert')
enc = gst.element_factory_make("vorbisenc","encoder")
mux = gst.element_factory_make("oggmux", "mux")
self.sink = gst.element_factory_make("filesink","sink")
self.player.add(source,convert,enc,mux,self.sink)
gst.element_link_many(source,convert,enc,mux,self.sink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
gtk.main()
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:
self.player.set_state(gst.STATE_NULL)
err, debug = message.parse_error()
print "Error: %s" % err, debug