JPlayer - 同步播放曲目

时间:2014-10-20 12:01:38

标签: javascript jquery events jplayer

我已经设置了多个轨道的jPlayer,我希望自动播放全部同步,我已经添加了轨道并且它们都自动播放正常,如何在它们全部加载时让它们一起自动播放?我想我可以通过活动来做到这一点,但我不知道该怎么做。



<script type="text/javascript">
    $(document).ready(function() {
		$('.ui-slider-handle').draggable();   	    
		
		// Base Track   
	    $("#base-track").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Base Track",
	                mp3: "audio/track1/audio_test_layer_base.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3",
			preload: "auto",
	    	volume: 0.8,
	    	muted: false,    
	    }); 
	    
	    	    
	    
	    // Track 1   
	    $("#jquery_jplayer_1").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Layer 1",
	                mp3: "audio/track1/audio_test_layer1.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3, oga",
			preload: "auto",
	    	volume: 0.0,
	    	muted: false,    
	    }); 
	    
        $('#slider').slider({ 
        min: 0, 
		max: 1,
		range: "min",        
		step: 0.01, 
        value: 0,
        orientation: "horizontal",
             slide: function(event, ui) {
        			var volume = ui.value / 1;
        			$("#jquery_jplayer_1").jPlayer("volume", volume);
                    $('#scene1').css('opacity', ui.value)
    		 }             
        })
 
	    // Track 2   
	    $("#jquery_jplayer_2").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Layer 2",
	                mp3: "audio/track1/audio_test_layer2.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3",
			preload: "auto",
	    	volume: 0.3,
	    	muted: false,    
	    }); 
	    
	    $('#slider2').slider({ 
        min: 0, 
        max: 1, 
        step: 0.01, 
        value: 0.3,
        orientation: "horizontal",
             slide: function(event, ui) {
        			var volume = ui.value / 1;
        			$("#jquery_jplayer_2").jPlayer("volume", volume);
                    $('#scene2').css('opacity', ui.value)
    		 }                 
        }) 

	    // Track 3   
	    $("#jquery_jplayer_3").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Layer 3",
	                mp3: "audio/track1/audio_test_layer3.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3",
			preload: "auto",
	    	volume: 0.0,
	    	muted: false,    
	    }); 
	    
	    $('#slider3').slider({ 
        min: 0, 
        max: 1, 
        step: 0.01, 
        value: 0,
        orientation: "horizontal",
             slide: function(event, ui) {
        			var volume = ui.value / 1;
        			$("#jquery_jplayer_3").jPlayer("volume", volume);
                    $('#scene3').css('opacity', ui.value)
    		 }                 
        }) 
    
	    // Track 4   
	    $("#jquery_jplayer_4").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Layer 4",
	                mp3: "audio/track1/audio_test_layer4.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3",
			preload: "auto",
	    	volume: 0,
	    	muted: false,    
	    }); 
	    
	    $('#slider4').slider({ 
        min: 0, 
        max: 1, 
        step: 0.01, 
        value: 0,
        orientation: "horizontal",
             slide: function(event, ui) {
        			var volume = ui.value / 1;
        			$("#jquery_jplayer_4").jPlayer("volume", volume);
                    $('#scene4').css('opacity', ui.value)
    		 }                 
        }) 


	    // Track 5   
	    $("#jquery_jplayer_5").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Layer 5",
	                mp3: "audio/track1/audio_test_layer5.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3",
			preload: "auto",
	    	volume: 0.8,
	    	muted: false,    
	    }); 
	    
	    $('#slider5').slider({ 
        min: 0, 
        max: 1, 
        step: 0.01, 
        value: 0.8,
        orientation: "horizontal",
             slide: function(event, ui) {
        			var volume = ui.value / 1;
        			$("#jquery_jplayer_5").jPlayer("volume", volume);
                    $('#scene5').css('opacity', ui.value)
    		 }                 
        }) 

	    // Track 6   
	    $("#jquery_jplayer_6").jPlayer({
	        ready: function(event) {
	            $(this).jPlayer("setMedia", {
	                title: "Layer 6",
	                mp3: "audio/track1/audio_test_layer6.mp3"
	    	}).jPlayer("play");
	  	},
	  		ended: function() {
	    		$(this).jPlayer("play");
	  		},
	        swfPath: "/js",
	        supplied: "mp3",
			preload: "auto",
	    	volume: 0.0,
	    	muted: false,    
	    }); 
	    
	    $('#slider6').slider({ 
        min: 0, 
        max: 1, 
        step: 0.01, 
        value: 0,
        orientation: "horizontal",
             slide: function(event, ui) {
        			var volume = ui.value / 1;
        			$("#jquery_jplayer_6").jPlayer("volume", volume);
                    $('#scene6').css('opacity', ui.value)
    		 }                 
        })         
        
        
    });</script>  
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您可以添加预加载:&#39; auto&#39;到了jplayer 如 jPlayer支持HTML5 preload参数,这样就可以添加preload:&#39; auto&#39;将加载后的曲目开始播放,这样所有的曲目都会在同一时间播放。

第3轨的示例:

$("#jquery_jplayer_3").jPlayer({
        ready: function(event) {
            $(this).jPlayer("setMedia", {
                title: "Layer 3",
                mp3: "audio/track1/audio_test_layer3.mp3"
        }).jPlayer("play");
    },
        ended: function() {
            $(this).jPlayer("play");
        },
        preload: 'auto',//here add it to all tracks
        swfPath: "/js",
        supplied: "mp3",
        preload: "auto",
        volume: 0.0,
        muted: false,    
    }); 

我希望它能帮到你

度过愉快的一天