garrett (owner)

Revisions

gist: 86098 Download_button fork
public
Public Clone URL: git://gist.github.com/86098.git
Embed All Files: show embed
jquery.soundmanager.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* from http://getsatisfaction.com/schillmania/topics/using_soundmanager_2_as_jquery_plugin
*/
 
$.playable = function( url, settings ) {
  var sm = soundManager,
  playable = arguments.callee;
  sm.url = url;
  sm.consoleOnly = window.location.hash.match(/console$/i);
  sm.debugMode = window.location.hash.match(/^#debug/i);
  $.extend( sm.defaultOptions,
    {
      autoStart : false,
      autoNext : true,
      pauseSkip : true,
      playAlone : true,
      doUnload : false,
      css : {
        playable: 'playable',
        playing : 'playing',
        paused : 'paused'
      },
      onload : function() {
        if ( this.readyState == 2 )
        playable.next.call( this );
      },
      onplay : function() {
        var options = this.options,
        current = options.element.removeClass( options.css.paused ).addClass( options.css.playing ).focus();
        if ( playable.current && playable.current != current )
        playable.current.data( 'playable' )[ options.pauseSkip ? 'pause' : 'stop' ]();
        if ( options.playAlone )
        playable.current = current;
      },
      onstop : function() {
        var options = this.options;
        options.element.removeClass( options.css.playing + ' ' + options.css.paused );
        if ( options.doUnload )
        this.unload();
      },
      onpause : function() {
        var options = this.options;
        options.element.removeClass( options.css.playing ).addClass( options.css.paused );
      },
      onresume : function() {
        this.options.onplay.call( this );
      },
      onfinish : function() {
        var options = this.options;
        if ( options.autoNext )
        playable.next.call( this );
        options.onstop.call( this );
      }
    },
    settings
  );
 
  $.extend(playable, {
    count : 0,
    current : null,
    init : function( options ) {
      var self = this,
      options = $.extend( true, {}, sm.defaultOptions, options );
      this.addClass( options.css.playable )
      .click( function( event ) {
        event.preventDefault();
        $( this ).data( 'playable' ).togglePause();
      } )
      .each( function() {
        $( this ).data( 'playable', sm.createSound( $.extend(
          {
            id : 'playable' + playable.count++,
            url : this.href,
            element : $( this ),
            selector: self.selector
          },
          options
        ) ) );
      } );
      if ( options.autoStart )
      self.filter( ':first' ).click();
    },
    next : function() {
      var options = this.options,
      next = $( options.element ).next( options.selector ).data( 'playable' );
      if ( next && ! next.playState )
      next.play();
    }
  });
};
 
$.fn.playable = function( options ) {
  var self = this.is( 'a[href]' ) ? this : this.find( 'a[href]' );
  soundManager.onload = function() {
    if ( soundManager.canPlayURL( self.attr( 'href' ) ) )
    $.playable.init.call( self, options );
  };
};
 
$(function(){
  /* Simple usage */
  $.playable('soundmanager/swf/');
  $('a').playable();
 
  /* Full usage, with options
$.playable('soundmanager/swf/', { //options used here are stored as soundManager.defaultOptions
// You can use all SM2 default options, plus the following:
autoStart : false, // Start playing the first item
autoNext : false, // Play next itemwhen previous ends
pauseSkip : false, // Just pause previous on skip
playAlone : false, // Force stop/pause previous on skip
doUnload : false // Unload sound on stop/finish
});
 
//Example configurations
$('.playlist').playable({autoStart: true, autoNext: true, playAlone: true, doUnload: false});
$('.sampler').playable({autoStart: false, autoNext: false, playAlone: true});
$('.listen').playable({autoStart: false, autoNext: false, playAlone: true,pauseSkip: true, doUnload: true});
*/
});