diff --git a/bower.json b/bower.json index 4c950e2..3c54bd9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ion.sound", - "version": "2.1.1", + "version": "2.1.2", "homepage": "https://github.com/IonDen/ion.sound", "authors": [ { diff --git a/ion-sound.jquery.json b/ion-sound.jquery.json index d5940c7..5100851 100644 --- a/ion-sound.jquery.json +++ b/ion-sound.jquery.json @@ -1,6 +1,6 @@ { "name": "ion-sound", - "version": "2.1.1", + "version": "2.1.2", "title": "Ion.Sound", "description": "JavaScript plugin for playing sounds on user actions and events. Today websites are full of events (new mail, new chat-message, content update etc.). Often it is not enough to indicate this events only visually to get user attention. You need sounds! This library, made for playing small sounds, will help you with this task.", "keywords": [ @@ -29,7 +29,7 @@ "homepage": "https://github.com/IonDen/ion.sound", "docs": "https://github.com/IonDen/ion.sound/blob/master/readme.md", "demo": "http://ionden.com/a/plugins/ion.sound/en.html", - "download": "http://ionden.com/a/plugins/ion.sound/ion.sound-2.1.0.zip", + "download": "http://ionden.com/a/plugins/ion.sound/ion.sound-2.1.2.zip", "dependencies": { "jquery": ">=1.3" } diff --git a/js/ion.sound.js b/js/ion.sound.js index 926ca4c..4268b3e 100644 --- a/js/ion.sound.js +++ b/js/ion.sound.js @@ -1,6 +1,6 @@ /** * Ion.Sound - * version 2.1.1 Build 43 + * version 2.1.2 Build 45 * © 2014 Denis Ineshin | IonDen.com * * Project page: http://ionden.com/a/plugins/ion.sound/en.html @@ -43,7 +43,10 @@ var ion = ion || {}; - var settings = {}, + var Sound, + is_iOS = /iPad|iPhone/.test(navigator.appVersion), + global_sound, + settings = {}, sounds = {}, sounds_num, ext, @@ -51,125 +54,183 @@ var ion = ion || {}; - var Sound = function (options) { - this.name = options.name; - this.volume = settings.volume || 0.5; - this.preload = settings.preload ? "auto" : "none"; - this.loop = false; - this.paused = false; - this.sound = null; - this.callback = null; - - if ("volume" in options) { - this.volume = +options.volume; - } + if (is_iOS) { - if ("preload" in options) { - this.preload = options.preload ? "auto" : "none" - } - }; + Sound = function (options) { + this.name = options.name; + this.loop = false; + this.paused = false; + this.sound = null; + this.callback = null; + }; - Sound.prototype = { - init: function () { - this.sound = new Audio(); - this.sound.src = settings.path + this.name + ext; - this.sound.load(); - this.sound.preload = this.preload; - this.sound.volume = this.volume; + Sound.prototype = { + init: function () { + this.sound = global_sound; + }, - this.sound.addEventListener("ended", this._ended.bind(this), false); - }, + play: function (obj) { + if (!obj) { + obj = {}; + } - play: function (obj) { - if (!obj) { - obj = {}; - } + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } - if (obj.volume || obj.volume === 0) { - this.volume = +obj.volume; - this.sound.volume = this.volume; - } + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, - if (obj.loop) { + _play: function () { if (this.paused) { - this._playLoop(this.loop + 1); + this.paused = false; } else { - this._playLoop(obj.loop); + try { + this.sound.currentTime = 0; + } catch (e) {} } - } else { - this.loop = false; - this._play(); - } - if (obj.onEnded && typeof obj.onEnded === "function") { - this.callback = obj.onEnded; - } - }, - - _play: function () { - if (this.paused) { - this.paused = false; - } else { - try { - this.sound.currentTime = 0; - } catch (e) {} + this.sound.removeEventListener("ended"); + this.sound.addEventListener("ended", this._ended.bind(this), false); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.play(); } + } + + } else { + + Sound = function (options) { + this.name = options.name; + this.volume = settings.volume || 0.5; + this.preload = settings.preload ? "auto" : "none"; + this.loop = false; + this.paused = false; + this.sound = null; + this.callback = null; - this.sound.play(); - }, - - _playLoop: function (loop) { - if (typeof loop === "boolean") { - // FF 3.6 and iOS, - // sound.loop = true not supported or buggy - this.loop = 9999999; - this._play(); - } else if (typeof loop === "number") { - this.loop = loop - 1; - this._play(); + if ("volume" in options) { + this.volume = +options.volume; } - }, - _ended: function () { - if (this.loop > 0) { - this.loop -= 1; - this._play(); + if ("preload" in options) { + this.preload = options.preload ? "auto" : "none" } + }; + + Sound.prototype = { + init: function () { + this.sound = new Audio(); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.preload = this.preload; + this.sound.volume = this.volume; + + this.sound.addEventListener("ended", this._ended.bind(this), false); + }, + + play: function (obj) { + if (!obj) { + obj = {}; + } - if (this.callback) { - this.callback(this.name); + if (obj.volume || obj.volume === 0) { + this.volume = +obj.volume; + this.sound.volume = this.volume; + } + + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } + + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, + + _play: function () { + if (this.paused) { + this.paused = false; + } else { + try { + this.sound.currentTime = 0; + } catch (e) {} + } + + this.sound.play(); } - }, + }; - pause: function () { - this.paused = true; - this.sound.pause(); - }, + } - stop: function () { - this.loop = false; - this.sound.pause(); + Sound.prototype._playLoop = function (loop) { + if (typeof loop === "boolean") { + // FF 3.6 and iOS, + // sound.loop = true not supported or buggy + this.loop = 9999999; + this._play(); + } else if (typeof loop === "number") { + this.loop = loop - 1; + this._play(); + } + }; - try { - this.sound.currentTime = 0; - } catch (e) {} - }, + Sound.prototype._ended = function () { + if (this.loop > 0) { + this.loop -= 1; + this._play(); + } - destroy: function () { - this.stop(); - this.sound.removeEventListener("ended", this._ended.bind(this), false); - this.sound.src = ""; - this.sound = null; + if (this.callback) { + this.callback(this.name); } }; + Sound.prototype.pause = function () { + this.paused = true; + this.sound.pause(); + }; + + Sound.prototype.stop = function () { + this.loop = false; + this.sound.pause(); + + try { + this.sound.currentTime = 0; + } catch (e) {} + }; + + Sound.prototype.destroy = function () { + this.stop(); + this.sound.removeEventListener("ended", this._ended.bind(this), false); + this.sound.src = ""; + this.sound = null; + }; + var checkSupport = function () { - var sound_item = new Audio(), - can_play_mp3 = sound_item.canPlayType("audio/mpeg"), - can_play_ogg = sound_item.canPlayType("audio/ogg; codecs='vorbis'"), - can_play_aac = sound_item.canPlayType("audio/mp4; codecs='mp4a.40.2'"); + global_sound = new Audio(); + + var can_play_mp3 = global_sound.canPlayType('audio/mpeg'), + can_play_ogg = global_sound.canPlayType('audio/ogg'), + can_play_aac = global_sound.canPlayType('audio/mp4'); if (can_play_mp3 === "probably") { ext = ".mp3"; @@ -186,8 +247,6 @@ var ion = ion || {}; } else { ext = ".wav"; } - - sound_item = null; }; var createSound = function (obj) { @@ -216,7 +275,7 @@ var ion = ion || {}; } }; - ion.sound.version = "2.0.2"; + ion.sound.version = "2.1.2"; ion.sound.play = function (name, options) { if (sounds[name]) { diff --git a/js/ion.sound.min.js b/js/ion.sound.min.js index 42088d4..1ec7283 100644 --- a/js/ion.sound.min.js +++ b/js/ion.sound.min.js @@ -1,2 +1,2 @@ -// Ion.Sound | version 2.1.1 | https://github.com/IonDen/ion.sound -var ion=ion||{};(function(c){var g=function(a){a&&console&&(console.warn&&"function"===typeof console.warn?console.warn(a):console.log&&"function"===typeof console.log&&console.log(a))};if(c.sound)g("ion.sound already exists!");else if("function"!==typeof Audio&&"object"!==typeof Audio){var f=function(){g("HTML5 Audio is not supported in this browser")};c.sound=function(){};c.sound.play=f;c.sound.stop=f;c.sound.destroy=f;f()}else{var e={},b={},h,k,d,l=function(a){this.name=a.name;this.volume=e.volume||.5;this.preload=e.preload?"auto":"none";this.paused=this.loop=!1;this.callback=this.sound=null;"volume"in a&&(this.volume=+a.volume);"preload"in a&&(this.preload=a.preload?"auto":"none")};l.prototype={init:function(){this.sound=new Audio;this.sound.src=e.path+this.name+k;this.sound.load();this.sound.preload=this.preload;this.sound.volume=this.volume;this.sound.addEventListener("ended",this._ended.bind(this),!1)},play:function(a){a||(a={});if(a.volume||0===a.volume)this.volume=+a.volume,this.sound.volume=this.volume;a.loop?this.paused?this._playLoop(this.loop+1):this._playLoop(a.loop):(this.loop=!1,this._play());a.onEnded&&"function"===typeof a.onEnded&&(this.callback=a.onEnded)},_play:function(){if(this.paused)this.paused=!1;else try{this.sound.currentTime=0}catch(a){}this.sound.play()},_playLoop:function(a){"boolean"===typeof a?(this.loop=9999999,this._play()):"number"===typeof a&&(this.loop=a-1,this._play())},_ended:function(){0 0) { - this.loop -= 1; - this._play(); + if ("preload" in options) { + this.preload = options.preload ? "auto" : "none" } + }; + + Sound.prototype = { + init: function () { + this.sound = new Audio(); + this.sound.src = settings.path + this.name + ext; + this.sound.load(); + this.sound.preload = this.preload; + this.sound.volume = this.volume; + + this.sound.addEventListener("ended", this._ended.bind(this), false); + }, + + play: function (obj) { + if (!obj) { + obj = {}; + } - if (this.callback) { - this.callback(this.name); + if (obj.volume || obj.volume === 0) { + this.volume = +obj.volume; + this.sound.volume = this.volume; + } + + if (obj.loop) { + if (this.paused) { + this._playLoop(this.loop + 1); + } else { + this._playLoop(obj.loop); + } + } else { + this.loop = false; + this._play(); + } + + if (obj.onEnded && typeof obj.onEnded === "function") { + this.callback = obj.onEnded; + } + }, + + _play: function () { + if (this.paused) { + this.paused = false; + } else { + try { + this.sound.currentTime = 0; + } catch (e) {} + } + + this.sound.play(); } - }, + }; - pause: function () { - this.paused = true; - this.sound.pause(); - }, + } - stop: function () { - this.loop = false; - this.sound.pause(); + Sound.prototype._playLoop = function (loop) { + if (typeof loop === "boolean") { + // FF 3.6 and iOS, + // sound.loop = true not supported or buggy + this.loop = 9999999; + this._play(); + } else if (typeof loop === "number") { + this.loop = loop - 1; + this._play(); + } + }; - try { - this.sound.currentTime = 0; - } catch (e) {} - }, + Sound.prototype._ended = function () { + if (this.loop > 0) { + this.loop -= 1; + this._play(); + } - destroy: function () { - this.stop(); - this.sound.removeEventListener("ended", this._ended.bind(this), false); - this.sound.src = ""; - this.sound = null; + if (this.callback) { + this.callback(this.name); } }; + Sound.prototype.pause = function () { + this.paused = true; + this.sound.pause(); + }; + + Sound.prototype.stop = function () { + this.loop = false; + this.sound.pause(); + + try { + this.sound.currentTime = 0; + } catch (e) {} + }; + + Sound.prototype.destroy = function () { + this.stop(); + this.sound.removeEventListener("ended", this._ended.bind(this), false); + this.sound.src = ""; + this.sound = null; + }; + var checkSupport = function () { - var sound_item = new Audio(), - can_play_mp3 = sound_item.canPlayType("audio/mpeg"), - can_play_ogg = sound_item.canPlayType("audio/ogg; codecs='vorbis'"), - can_play_aac = sound_item.canPlayType("audio/mp4; codecs='mp4a.40.2'"); + global_sound = new Audio(); + + var can_play_mp3 = global_sound.canPlayType('audio/mpeg'), + can_play_ogg = global_sound.canPlayType('audio/ogg'), + can_play_aac = global_sound.canPlayType('audio/mp4'); if (can_play_mp3 === "probably") { ext = ".mp3"; @@ -184,8 +245,6 @@ } else { ext = ".wav"; } - - sound_item = null; }; var createSound = function (obj) { @@ -214,7 +273,7 @@ } }; - $.ionSound.version = "2.0.2"; + $.ionSound.version = "2.1.2"; $.ionSound.play = function (name, options) { if (sounds[name]) { diff --git a/js/jquery.ion.sound.min.js b/js/jquery.ion.sound.min.js index 8060d82..1a0b575 100644 --- a/js/jquery.ion.sound.min.js +++ b/js/jquery.ion.sound.min.js @@ -1,2 +1,2 @@ -// jQuery.Ion.Sound | version 2.1.1 | https://github.com/IonDen/ion.sound -(function(c){var g=function(a){a&&console&&(console.warn&&"function"===typeof console.warn?console.warn(a):console.log&&"function"===typeof console.log&&console.log(a))};if(c.ionSound)g("$.ionSound already exists!");else if("function"!==typeof Audio&&"object"!==typeof Audio){var f=function(){g("HTML5 Audio is not supported in this browser")};c.ionSound=function(){};c.ionSound.play=f;c.ionSound.stop=f;c.ionSound.destroy=f;f()}else{var e={},b={},h,k,d,l=function(a){this.name=a.name;this.volume=e.volume||.5;this.preload=e.preload?"auto":"none";this.paused=this.loop=!1;this.callback=this.sound=null;"volume"in a&&(this.volume=+a.volume);"preload"in a&&(this.preload=a.preload?"auto":"none")};l.prototype={init:function(){this.sound=new Audio;this.sound.src=e.path+this.name+k;this.sound.load();this.sound.preload=this.preload;this.sound.volume=this.volume;this.sound.addEventListener("ended",this._ended.bind(this),!1)},play:function(a){a||(a={});if(a.volume||0===a.volume)this.volume=+a.volume,this.sound.volume=this.volume;a.loop?this.paused?this._playLoop(this.loop+1):this._playLoop(a.loop):(this.loop=!1,this._play());a.onEnded&&"function"===typeof a.onEnded&&(this.callback=a.onEnded)},_play:function(){if(this.paused)this.paused=!1;else try{this.sound.currentTime=0}catch(a){}this.sound.play()},_playLoop:function(a){"boolean"===typeof a?(this.loop=9999999,this._play()):"number"===typeof a&&(this.loop=a-1,this._play())},_ended:function(){0 English description | Описание на русском JavaScript plugin for playing sounds on user actions and page events. * Project page and demos -* Download ion.sound-2.1.1.zip +* Download ion.sound-2.1.2.zip *** @@ -204,6 +204,7 @@ ion.sound.destroy(); ## Update history +* 2.1.2: October 26, 2014 - Fixed bug in iOS 8.x #15 * 2.1.1: October 25, 2014 - Minor fix. * 2.1.0: October 25, 2014 - Fixed bug #12. AAC files support. Callback onEnded. * 2.0.2: August 08, 2014 - New pause method. Add bower support diff --git a/readme.ru.md b/readme.ru.md index 35004f1..b9042fa 100644 --- a/readme.ru.md +++ b/readme.ru.md @@ -1,10 +1,10 @@ -# Ion.Sound 2.1.1 +# Ion.Sound 2.1.2 > English description | Описание на русском JavaScript-плагин для воспроизведения звуков * Сайт проекта и демо -* Скачать ion.sound-2.1.1.zip +* Скачать ion.sound-2.1.2.zip *** @@ -202,6 +202,7 @@ ion.sound.destroy(); ## История обновлений +* 2.1.2: 26 октября 2014 - исправлен баг в iOS 8.x #15 * 2.1.1: 25 октября 2014 - мини-фикс. * 2.1.0: 25 октября 2014 - исправлен баг #12. Добавлена поддержка .aac. Добавен коллбэк onEnded. * 2.0.2: 08 августа 2014 - новый метод - пауза. Добавлена поддержка bower