Learn how to use jQuery at the Blog

QN5 Music « visit

  • Added 8 months ago
  • 78 Lines of Code shown
  • 1 Links of Interest
http://qn5.com
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to QN5 Music - http://qn5.com

/* Used in the music section of QN5.com */

QN5.Playlist = $.klass({
	initialize: function(playerId, li) {
		var $this = this;
		var sm = soundManager;

		$this.id = 'sound-' + playerId;
		$this.originalDocumentTitle = document.title;

		$this.player = $(li);

		$this.link = $this.player.find('a.control:first-child');
		$this.link.click(function(event) {
			event.preventDefault();
			if ( !$this.player.hasClass('playing') ) {
				sm.pauseAll();
			}
			sm.togglePause($this.id);
		});
		
		$this.permalink = $this.player.find('a.permalink:first');
		if ( !window.isIE6 ) {
			$this.permalink
				.mouseover(function() { $this.player.addClass('hover'); })
				.mouseout(function() { $this.player.removeClass('hover'); });	
		}

		$this.position = $this.player.find('span.position:first');

		sm.createSound({
			id:$this.id,
			url:$this.link.attr('href'),
			autoLoad:false,
			playNext:true,
			onplay: function() {
				$this.play(this, 'play');
			},
			onresume: function() {
				$this.play(this, 'resume');
			},
			onpause: function(){
				$this.pause();
			},
			onfinish: function() {
				$this.pause();
				$this.player.next('li').find('a.control:first').click();
			},
			whileloading: function() {
			},
			whileplaying: function() {
				$this.position.css('width', (((this.position/this.durationEstimate)*100)+'%'));
			}
		});
	},

	play: function(currentSound, type) {
		var $this = this;
		var sm = soundManager;

		if (type == 'play') {
			sm.play(currentSound);
		} else if (type == 'resume') {
			sm.resume(currentSound);
		}

		document.title = 'NOW PLAYING: ' + $this.link.attr('title');

		$this.player.addClass('playing').removeClass('paused');
	},

	pause: function() {
		var $this = this;
		document.title = $this.originalDocumentTitle;
		$this.player.removeClass('playing');
	}

});