Gstreamer 使用Vala将Scaletempo添加到playbin

Gstreamer 使用Vala将Scaletempo添加到playbin,gstreamer,vala,Gstreamer,Vala,我在Vala尝试将scaletempo与playbin一起使用时遇到问题。我创建了playbin,然后创建了一个bin来存储替换默认音频接收器的附加插件。下面的示例是我从pyTranscribe抓取并转换为Vala的,但是Element.link\u many导致了一个错误,我不太清楚原因 我这样做对吗?有人有其他建议吗 /* SoundPlayerBackend.vala */ /* Modified code from Damien Radtke's site. http://damienr

我在Vala尝试将scaletempo与playbin一起使用时遇到问题。我创建了playbin,然后创建了一个bin来存储替换默认音频接收器的附加插件。下面的示例是我从pyTranscribe抓取并转换为Vala的,但是Element.link\u many导致了一个错误,我不太清楚原因

我这样做对吗?有人有其他建议吗

/* SoundPlayerBackend.vala */
/* Modified code from Damien Radtke's site. http://damienradtke.org/ */

using Gst;
public class SoundPlayerBackend {

    //Constants
    const double PLAYBACK_RATE_MODIFIER = 2.0;
    const int SEEK_SECONDS = 10;

    // Method delegates for notifying SoundPlayer about certain events
    protected delegate void NotifyEos();
    protected delegate void NotifyError(string message);

    // Pointer to our EOS delegate
    protected NotifyEos on_eos; 

    // Pointer to our Error delegate
    protected NotifyError on_error; 

    public static void main(string[] args){
        var soundplayer = new SoundPlayerBackend();
        Gst.init(ref args);
        soundplayer.setUri("file:///home/codenomad/Desktop/player-project/hurricane.mp3");
        soundplayer.play();
        string stop = stdin.read_line ();

        while (stop != "stop") {
            if (stop == "pause") { soundplayer.pause(); }
            else if (stop == "play") { soundplayer.play(); }
            stop = stdin.read_line ();
        }
    }

    // Read-only reference to the current sound object
    public dynamic Element sound { get; private set; } 

    // Read-only "is playing" property
    public bool is_playing { get; private set; default = false; } 

    // Read-only "rate" property
    public double rate { get; private set; default = 1; } 

    public void setUri(string uri) {
        // Make sure any existing allocated resources are freed
        if (sound != null)
            sound.set_state(Gst.State.NULL);
        sound = ElementFactory.make("playbin2", "playbin");        
        sound.uri = uri;
        var audiobin = new Bin("audioline");
        var scaletempo = ElementFactory.make("scaletempo", "scaletempo");
        var convert    = ElementFactory.make("audioconvert", "convert");
        var resample   = ElementFactory.make("audioresample", "resample");
        var audiosink = ElementFactory.make("autoaudiosink", "audiosink");

        audiobin.add_many(scaletempo, convert, resample, audiosink);

        //edited based on comment below
        //Element.link_many(scaletempo, convert, resample, audiosink);
        scaletempo.link_many(convert, resample, audiosink);

        var pad = scaletempo.get_pad("sink");
        audiobin.add_pad(new GhostPad("sink", pad));
        sound.set_property("audio-sink", audiobin);    
        sound.get_bus().add_watch(on_event);
    }

    // Play the sound
    public void play() {
        sound.set_state(State.PLAYING);
        print("Playing\n");
        is_playing = true;
    }

    // Pause it
    public void pause() {
        sound.set_state(State.PAUSED);
        is_playing = false;
        print("Paused\n");
    }

    // Event bus, listens for events and responds accordingly
    protected bool on_event(Gst.Bus bus, Message message) {
        switch (message.type) {
            case MessageType.ERROR:
                GLib.Error err;
                string debug;
                sound.set_state(Gst.State.NULL);
                is_playing = false;
                message.parse_error(out err, out debug);
                on_error(err.message);
                break;
            case MessageType.EOS:
                sound.set_state(Gst.State.READY);
                is_playing = false;
                on_eos();
                break;
            default:
                break;
        }
        return true;
    }
}
我尝试使用相同的代码使所有内容保持静态,并收到相同的结果/错误,如下所示:

SoundPlayerBackend.vala:121.9-121.67: error: Access to instance member `Gst.Element.link_many' denied
Element.link_many(scaletempo, convert, resample, audiosink);
提前谢谢

那一行应该是

scaletempo.link_many(convert, resample, audiosink);
那一行应该是

scaletempo.link_many(convert, resample, audiosink);

谢谢你的回复!我做了更改,没有得到任何声音输出,我还收到了:(SoundPlayerBakend:18163):GLib GObject CRITICAL**:g_object\u ref:assertion
g_IS_object(object)(object)failed(SoundPlayerBakend:18163):GStreamer CRITICAL**:gst_元素集_状态:assertion
gst_IS元素(element)'failed(SoundPlayerBakend:18163):GStreamer CRITICAL**:gst\u element\u set\u state:assertion`gst\u IS\u element(element)'failedIt很难在不知道是什么代码导致的情况下找出警告。对此,我很抱歉,我刚刚添加了源代码的其余部分,我仍在挠头……也许在
sound
属性上设置
默认值=null
?尝试找出是哪个对
元素的调用。set_state()
导致了警告,然后您最好打开另一个问题,因为原始问题已得到回答。谢谢您的回答!我做了更改,没有得到任何声音输出,我还收到了:(SoundPlayerBakend:18163):GLib GObject CRITICAL**:g_object\u ref:assertion
g_IS_object(object)(object)failed(SoundPlayerBakend:18163):GStreamer CRITICAL**:gst_元素集_状态:assertion
gst_IS元素(element)'failed(SoundPlayerBakend:18163):GStreamer CRITICAL**:gst\u element\u set\u state:assertion`gst\u IS\u element(element)'failedIt很难在不知道是什么代码导致的情况下找出警告。对此,我很抱歉,我刚刚添加了源代码的其余部分,我仍在挠头……也许在
sound
属性上设置
默认值=null
?尝试找出是哪个对
元素的调用。set_state()
导致了警告,然后最好打开另一个问题,因为原来的问题已经得到了回答。