Skip to content

Commit

Permalink
Update to 2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
IonDen committed Oct 27, 2014
1 parent 397633a commit e7fecd8
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 205 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ion.sound",
"version": "2.1.1",
"version": "2.1.2",
"homepage": "https://github.com/IonDen/ion.sound",
"authors": [
{
Expand Down
4 changes: 2 additions & 2 deletions ion-sound.jquery.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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"
}
Expand Down
253 changes: 156 additions & 97 deletions js/ion.sound.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,133 +43,194 @@ var ion = ion || {};



var settings = {},
var Sound,
is_iOS = /iPad|iPhone/.test(navigator.appVersion),
global_sound,
settings = {},
sounds = {},
sounds_num,
ext,
i;



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";
Expand All @@ -186,8 +247,6 @@ var ion = ion || {};
} else {
ext = ".wav";
}

sound_item = null;
};

var createSound = function (obj) {
Expand Down Expand Up @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions js/ion.sound.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7fecd8

Please sign in to comment.