-
Notifications
You must be signed in to change notification settings - Fork 27
/
jquery.simpleplayer.min.js
1 lines (1 loc) · 2.03 KB
/
jquery.simpleplayer.min.js
1
(function(a){a.fn.player=function(e){var d={progressbarWidth:"200px",progressbarHeight:"5px",progressbarColor:"#22ccff",progressbarBGColor:"#eeeeee",defaultVolume:0.8};if(e){a.extend(d,e)}var c='<span class="simpleplayer-play-control"></span>';var b='<span class="simpleplayer-stop-control"></span>';this.each(function(){a(this).wrap('<div class="simple-player-container" style="background-color: #ddd; padding: 0 10px 5px 5px;" />').parent().prepend('<div><ul><li style="display: inline-block; padding: 0 5px; "><a style="text-decoration: none;" class="start-button" href="javascript:void(0)">'+c+'</a></li><li class="progressbar-wrapper" style="display: inline-block; cursor: pointer; width:'+d.progressbarWidth+';"><span style="display: block; background-color: '+d.progressbarBGColor+'; width: 100%; "><span class="progressbar" style="display: block; background-color: '+d.progressbarColor+"; height: "+d.progressbarHeight+'; width: 0%; "></span></span></li></ul></div>');var i=a(this).get(0);var h=a(this).parent().find(".start-button");var g=a(this).parent().find(".progressbar-wrapper");var f=a(this).parent().find(".progressbar");i.volume=d.defaultVolume;h.click(function(){if(i.paused){i.play();a(this).find(".simpleplayer-play-control").addClass("simpleplayer-stop-control").removeClass("simpleplayer-play-control")}else{i.pause();a(this).find(".simpleplayer-stop-control").addClass("simpleplayer-play-control").removeClass("simpleplayer-stop-control")}});g.click(function(j){if(i.duration!=0){left=a(this).offset().left;offset=j.pageX-left;percent=offset/g.width();duration_seek=percent*i.duration;i.currentTime=duration_seek}});a(i).bind("ended",function(j){i.pause();h.find(".simpleplayer-stop-control").addClass("simpleplayer-play-control").removeClass("simpleplayer-stop-control");f.css("width","0%")});a(i).bind("timeupdate",function(j){duration=this.duration;time=this.currentTime;fraction=time/duration;percent=fraction*100;if(percent){f.css("width",percent+"%")}});if(i.duration>0){a(this).parent().css("display","inline-block")}});return this}})(jQuery);