【问题标题】:Changing target of an embed vlc video更改嵌入 vlc 视频的目标
【发布时间】:2014-06-25 21:37:29
【问题描述】:

我正在尝试根据用户的选择更改 vlc 视频的目标/来源。这是我目前所拥有的:

$('select').change(function() {
            var router = $(this).val();
            alert("The port number is "+router);

            var link = "http://xxx:"+router+"/videostream.cgi?user=admin&pwd=cam1&t=";
            alert("The stored link is: "+link);

            alert("The current target is: "+$("#vlc").attr("target"));

            $("#vlc").attr("target",link);

            alert("The new target is: "+$("#vlc").attr("target",link));

        });

选择:

<select name="cameras" id="cameras">
    <option value="1101">Cam 1</option>
    <option value="1102">Cam 2</option>
</select>

vlc 对象:

<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org" version="VideoLAN.VLCPlugin.2"  width="500"  height="500" id="vlc" loop="yes" autoplay="yes" target="http://xxx:1101/videostream.cgi?user=admin&pwd=cam1&t="></embed>

xxx 指用户的IP。这些警报是出于我自己的测试目的。前三个正常运行,但最后一个返回 [object Object]。我已经能够更改 vlc 对象的其他属性,例如宽度,所以这是我缺少的目标属性的东西

【问题讨论】:

  • 最后一个警报返回 [object Object] 因为 jQuery 调用返回的是 jQuery 节点对象,而只是提醒 link。您是否尝试过使用prop() 而不是attr() 来更改目标?
  • 原来我不需要最后一个链接。它现在正在正确地警告目标。然而,尽管改变了目标,但视频并没有改变。我想这是新问题。
  • 看看这个:forum.videolan.org/viewtopic.php?f=16&t=57845 看起来你可以做到vlc.playlist.playItem( vlc.playlist.add('http://xyz') );

标签: javascript jquery embed vlc target


【解决方案1】:

在更改 target 属性之前,您必须从 DOM 中分离 &lt;embed&gt; 元素。然后再贴一次。

var embed, embedParent;

$('select').change(function() {
    var router = $(this).val();

    alert("The port number is "+router);

    var link = "http://xxx:"+router+"/videostream.cgi?user=admin&pwd=cam1&t=";
    alert("The stored link is: "+link);

    alert("The current target is: "+$("#vlc").attr("target"));

    // getting parent for further use
    embedParent = $("#vlc").parent();

    // will remove element from DOM and assing to embed var
    embed = $("#vlc").detach();
    embed.attr("target", link);
    embed.appendTo(embedParent);
});

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    相关资源
    最近更新 更多