1

您好,这是我第一次在网上提问。我想在我的 wordpress 网站中嵌入一个 youtube 频道播放器。我正在使用来自http://code.google.com/p/jq-youtube-player/的代码。所以我希望这个播放器在加载时自动播放并且音频静音。我只能将自动播放设置为打开,但不知道如何使音频静音。我正在http://jsfiddle.net/NmvA9/490/上尝试一些东西,但我是 java 脚本的初学者,所以需要帮助。

代码是这样的

(function() {
    function createPlayer(jqe, video, options) {
        var ifr = $('iframe', jqe);
    if (ifr.length === 0) {
        ifr = $('<iframe scrolling="no">');
        ifr.addClass('player');
    }
    var src = 'http://www.youtube.com/embed/' + video.id + '?enablejsapi=1';
    if (options.playopts) {
        src += '?';
        for (var k in options.playopts) {
            src+= k + '=' + options.playopts[k] + '&';
        }  
        src += '_a=b';
    }
    ifr.attr('src', src);
    jqe.append(ifr);  
}

function createCarousel(jqe, videos, options) {
    var car = $('div.carousel', jqe);
    if (car.length === 0) {
        car = $('<div>');
        car.addClass('carousel');
        jqe.append(car);

    }
    $.each(videos, function(i,video) {
        options.thumbnail(car, video, options);
    });
}

function createThumbnail(jqe, video, options) {
    var imgurl = video.thumbnails[0].url;
    var img = $('img[src="' + imgurl + '"]');
    if (img.length !== 0) return;
    img = $('<img>');    
    img.addClass('thumbnail');
    jqe.append(img);
    img.attr('src', imgurl);
    img.attr('title', video.title);
    img.click(function() {
        options.player(options.maindiv, video, $.extend(true,{},options,{playopts:{autoplay:1}}));
    });
}

var defoptions = {
    autoplay: false,
    user: null,
    carousel: createCarousel,
    player: createPlayer,
    thumbnail: createThumbnail,
    loaded: function() {},
    playopts: {
        autoplay: 0,
        egm: 1,
        autohide: 1,
        fs: 1,
        showinfo: 0
    }
};
player.mute():Void

$.fn.extend({
    youTubeChannel: function(options) {
        var md = $(this);
        md.addClass('youtube');
        md.addClass('youtube-channel');
        var allopts = $.extend(true, {}, defoptions, options);
        allopts.maindiv = md;
        $.getJSON('http://gdata.youtube.com/feeds/users/' + allopts.user + '/uploads?alt=json-in-script&format=5&callback=?', null, function(data) {
            var feed = data.feed;
            var videos = [];
            $.each(feed.entry, function(i, entry) {
                var video = {
                    title: entry.title.$t,
                    id: entry.id.$t.match('[^/]*$'),
                    thumbnails: entry.media$group.media$thumbnail
                };
                videos.push(video);
            });
            allopts.allvideos = videos;
            allopts.carousel(md, videos, allopts);
            allopts.player(md, videos[0], allopts);
            allopts.loaded(videos, allopts);
        });
    }
});

 })();

$(function() {
$('#player').youTubeChannel({user:'youtube'});
});

如果在此代码中将自动播放设置为“1”

var defoptions = {
    autoplay: false,
    user: null,
    carousel: createCarousel,
    player: createPlayer,
    thumbnail: createThumbnail,
    loaded: function() {},
    playopts: {
        autoplay: 0,
        egm: 1,
        autohide: 1,
        fs: 1,
        showinfo: 0
    }
};

它会自动播放视频,但添加“静音”值似乎不起作用。我想我需要以其他方式将其静音,但不知道如何...所以请帮忙谢谢

4

0 回答 0