[英]Python gst segmentation fault
I want to create a player class to play music with gst. 我想创建一个播放器类来播放GST音乐。 This ist the code:
这是代码:
from gi.repository import GObject
GObject.threads_init()
import gst
class PlayerControl:
def __init__(self, main_window):
self.player = gst.element_factory_make("playbin2", "player")
self.sink = gst.element_factory_make("autoaudiosink", "player Output")
self.videosink= gst.element_factory_make("fakesink", "player fake Output")
self.player.set_property("video-sink", self.videosink)
self.player.set_property("audio-sink", self.sink)
self.player_bus = self.player.get_bus()
self.player_bus.add_signal_watch()
self.player_bus.connect("message", self.on_messages)
self.player.connect("about-to-finish", self.on_finish)
self.main_window = main_window
self.main_window.seek_bar.connect("value-changed", self.on_slider_changed)
self.main_window.seek_bar.set_range(0, 100)
self.playing = False
def on_messages(self, bus, message):
print(message)
def play(self, file):
self.playing = True
self.player.set_state(gst.STATE_READY)
self.player.set_property("uri", "file:///"+str(file)) # örnek olsun diye
self.player.set_state(gst.STATE_PLAYING)
GObject.timeout_add(100, self.update_slider)
[...]
I'm calling this from another class like this to play sound: 我从另一个这样的班级叫这来播放声音:
from file import PlayerControl
class PlayerExample():
def __init__( self ):
self.player_gst = PlayerControl(self)
[...]
def play(self, file):
self.playing = True
self.player.set_state(gst.STATE_READY)
self.player.set_property("uri", "file:///"+str(file))
self.player.set_state(gst.STATE_PLAYING)
GObject.timeout_add(100, self.update_slider)
[...]
I've connected a gtk button to play function. 我已连接一个gtk按钮以播放功能。 When i clicked the button i take
segmentation fault
without any information. 当我单击按钮时,我遇到了没有任何信息的
segmentation fault
。 Also if i remove self.player_bus.add_signal_watch()
and self.player.connect("about-to-finish", self.on_finish)
lines from my PlayerControl class, it works and play sound but i need to call on_finished function with "about-to-finish" signal. 另外,如果我从PlayerControl类中删除
self.player_bus.add_signal_watch()
和self.player.connect("about-to-finish", self.on_finish)
行,则它可以正常工作并播放声音,但我需要使用“即将完成”信号。 Why it doesn't work? 为什么不起作用?
GObject.threads_init()
from gi.repository doesn't work with pygst "0.10" you need to add: GObject.threads_init()
无法与pygst“ 0.10”配合使用,您需要添加:
import gobject
gobject.threads_init()
import gst
top of the player class. 顶级玩家。 Or use Gst-1.0 https://wiki.ubuntu.com/Novacut/GStreamer1.0
或使用Gst-1.0 https://wiki.ubuntu.com/Novacut/GStreamer1.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.