Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

soundcloud-audio

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soundcloud-audio - npm Package Compare versions

Comparing version 1.2.2 to 1.3.1

25

dist/soundcloud-audio.js

@@ -1,2 +0,2 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.SoundCloudAudio=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/dmitri/github/soundcloud-html5-audio":[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SoundCloudAudio = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
'use strict';

@@ -159,3 +159,7 @@

if (length) {
this._playlistIndex = options.playlistIndex || 0;
if (options.playlistIndex === undefined) {
this._playlistIndex = this._playlistIndex || 0;
} else {
this._playlistIndex = options.playlistIndex;
}

@@ -187,3 +191,3 @@ // be silent if index is out of range

this.audio.play();
return this.audio.play();
};

@@ -202,11 +206,16 @@

SoundCloud.prototype.next = function () {
SoundCloud.prototype.next = function (options) {
options = options || {};
var tracksLength = this._playlist.tracks.length;
if (this._playlistIndex >= tracksLength - 1) {
return;
if (options.loop) {
this._playlistIndex = -1;
} else {
return;
}
}
if (this._playlist && tracksLength) {
this.play({playlistIndex: ++this._playlistIndex});
return this.play({playlistIndex: ++this._playlistIndex});
}

@@ -221,3 +230,3 @@ };

if (this._playlist && this._playlist.tracks.length) {
this.play({playlistIndex: --this._playlistIndex});
return this.play({playlistIndex: --this._playlistIndex});
}

@@ -259,3 +268,3 @@ };

},{}]},{},["/Users/dmitri/github/soundcloud-html5-audio"])("/Users/dmitri/github/soundcloud-html5-audio")
},{}]},{},[1])(1)
});

@@ -1,1 +0,1 @@

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.SoundCloudAudio=t()}}(function(){return function t(e,i,o){function n(r,a){if(!i[r]){if(!e[r]){var l="function"==typeof require&&require;if(!a&&l)return l(r,!0);if(s)return s(r,!0);var u=new Error("Cannot find module '"+r+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[r]={exports:{}};e[r][0].call(d.exports,function(t){var i=e[r][1][t];return n(i?i:t)},d,d.exports,t,e,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r<o.length;r++)n(o[r]);return n}({1:[function(t,e){"use strict";function i(t){s||(s=document.createElement("a"));var e={};s.href=t||"";for(var i=0,o=r.length;o>i;i++){var n=r[i];e[n]=s[n]}return e}function o(t,e,o){var n=i(t),s=/\?(?:.*)$/,r=s.test(n.search)?"&":"?",a=n.protocol+"//"+n.host+n.port+n.pathname+n.search+r+e+"="+o+n.hash;return a}function n(t){return this instanceof n?(t||console.info("SoundCloud API requires clientId, get it at https://developers.soundcloud.com"),this._events={},this._clientId=t,this._baseUrl="https://api.soundcloud.com",this.playing=!1,this.duration=0,void(this.audio=document.createElement("audio"))):new n(t)}var s,r="protocol hostname host pathname port search hash href".split(" ");n.prototype.resolve=function(t,e){var o=this._baseUrl+"/resolve.json?url="+encodeURIComponent(t)+"&client_id="+this._clientId;this._json(o,function(o){if(this.cleanData(),Array.isArray(o)){var n=o;o={tracks:n},this._playlist=o}else if(o.tracks)this._playlist=o;else{this._track=o;var s=i(t);this._track.stream_url+=s.hash}this.duration=o.duration&&!isNaN(o.duration)?o.duration/1e3:0,e(o)}.bind(this))},n.prototype._jsonp=function(t,e){var i=document.getElementsByTagName("script")[0]||document.head,n=document.createElement("script"),s="jsonp_callback_"+(new Date).valueOf()+Math.floor(1e3*Math.random());window[s]=function(t){n.parentNode&&n.parentNode.removeChild(n),window[s]=function(){},e(t)},n.src=o(t,"callback",s),i.parentNode.insertBefore(n,i)},n.prototype._json=function(t,e){var i=new XMLHttpRequest;i.open("GET",t),i.onreadystatechange=function(){if(4===i.readyState&&200===i.status){var t={};try{t=JSON.parse(i.responseText)}catch(o){}e(t)}},i.send(null)},n.prototype.on=function(t,e){this._events[t]=e,this.audio.addEventListener(t,e,!1)},n.prototype.off=function(t,e){this._events[t]=null,this.audio.removeEventListener(t,e)},n.prototype.unbindAll=function(){for(var t in this._events){var e=this._events[t];e&&this.off(t,e)}},n.prototype.preload=function(t,e){this._track={stream_url:t},e&&(this.audio.preload=e),this.audio.src=this._clientId?o(t,"client_id",this._clientId):t},n.prototype.play=function(t){t=t||{};var e;if(t.streamUrl)e=t.streamUrl;else if(this._playlist){var i=this._playlist.tracks.length;if(i){if(this._playlistIndex=t.playlistIndex||0,this._playlistIndex>=i||this._playlistIndex<0)return void(this._playlistIndex=0);e=this._playlist.tracks[this._playlistIndex].stream_url}}else this._track&&(e=this._track.stream_url);if(!e)throw new Error("There is no tracks to play, use `streamUrl` option or `load` method");this._clientId&&(e=o(e,"client_id",this._clientId)),e!==this.audio.src&&(this.audio.src=e),this.playing=e,this.audio.play()},n.prototype.pause=function(){this.audio.pause(),this.playing=!1},n.prototype.stop=function(){this.audio.pause(),this.audio.currentTime=0,this.playing=!1},n.prototype.next=function(){var t=this._playlist.tracks.length;this._playlistIndex>=t-1||this._playlist&&t&&this.play({playlistIndex:++this._playlistIndex})},n.prototype.previous=function(){this._playlistIndex<=0||this._playlist&&this._playlist.tracks.length&&this.play({playlistIndex:--this._playlistIndex})},n.prototype.seek=function(t){if(!this.audio.readyState)return!1;var e=t.offsetX/t.target.offsetWidth||(t.layerX-t.target.offsetLeft)/t.target.offsetWidth;this.audio.currentTime=e*(this.audio.duration||0)},n.prototype.cleanData=function(){this._track=void 0,this._playlist=void 0},n.prototype.setVolume=function(t){this.audio.readyState&&(this.audio.volume=t)},n.prototype.setTime=function(t){this.audio.readyState&&(this.audio.currentTime=t)},e.exports=n},{}]},{},[1])(1)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).SoundCloudAudio=t()}}(function(){return function t(e,i,n){function o(r,a){if(!i[r]){if(!e[r]){var l="function"==typeof require&&require;if(!a&&l)return l(r,!0);if(s)return s(r,!0);var u=new Error("Cannot find module '"+r+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[r]={exports:{}};e[r][0].call(d.exports,function(t){var i=e[r][1][t];return o(i||t)},d,d.exports,t,e,i,n)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r<n.length;r++)o(n[r]);return o}({1:[function(t,e,i){"use strict";var n,o="protocol hostname host pathname port search hash href".split(" ");function s(t){n||(n=document.createElement("a"));var e={};n.href=t||"";for(var i=0,s=o.length;i<s;i++){var r=o[i];e[r]=n[r]}return e}function r(t,e,i){var n=s(t),o=/\?(?:.*)$/.test(n.search)?"&":"?";return n.protocol+"//"+n.host+n.port+n.pathname+n.search+o+e+"="+i+n.hash}function a(t){if(!(this instanceof a))return new a(t);t||console.info("SoundCloud API requires clientId, get it at https://developers.soundcloud.com"),this._events={},this._clientId=t,this._baseUrl="https://api.soundcloud.com",this.playing=!1,this.duration=0,this.audio=document.createElement("audio")}a.prototype.resolve=function(t,e){var i=this._baseUrl+"/resolve.json?url="+encodeURIComponent(t)+"&client_id="+this._clientId;this._json(i,function(i){if(this.cleanData(),Array.isArray(i))i={tracks:i},this._playlist=i;else if(i.tracks)this._playlist=i;else{this._track=i;var n=s(t);this._track.stream_url+=n.hash}this.duration=i.duration&&!isNaN(i.duration)?i.duration/1e3:0,e(i)}.bind(this))},a.prototype._jsonp=function(t,e){var i=document.getElementsByTagName("script")[0]||document.head,n=document.createElement("script"),o="jsonp_callback_"+(new Date).valueOf()+Math.floor(1e3*Math.random());window[o]=function(t){n.parentNode&&n.parentNode.removeChild(n),window[o]=function(){},e(t)},n.src=r(t,"callback",o),i.parentNode.insertBefore(n,i)},a.prototype._json=function(t,e){var i=new XMLHttpRequest;i.open("GET",t),i.onreadystatechange=function(){if(4===i.readyState&&200===i.status){var t={};try{t=JSON.parse(i.responseText)}catch(t){}e(t)}},i.send(null)},a.prototype.on=function(t,e){this._events[t]=e,this.audio.addEventListener(t,e,!1)},a.prototype.off=function(t,e){this._events[t]=null,this.audio.removeEventListener(t,e)},a.prototype.unbindAll=function(){for(var t in this._events){var e=this._events[t];e&&this.off(t,e)}},a.prototype.preload=function(t,e){this._track={stream_url:t},e&&(this.audio.preload=e),this.audio.src=this._clientId?r(t,"client_id",this._clientId):t},a.prototype.play=function(t){var e;if((t=t||{}).streamUrl)e=t.streamUrl;else if(this._playlist){var i=this._playlist.tracks.length;if(i){if(void 0===t.playlistIndex?this._playlistIndex=this._playlistIndex||0:this._playlistIndex=t.playlistIndex,this._playlistIndex>=i||this._playlistIndex<0)return void(this._playlistIndex=0);e=this._playlist.tracks[this._playlistIndex].stream_url}}else this._track&&(e=this._track.stream_url);if(!e)throw new Error("There is no tracks to play, use `streamUrl` option or `load` method");return this._clientId&&(e=r(e,"client_id",this._clientId)),e!==this.audio.src&&(this.audio.src=e),this.playing=e,this.audio.play()},a.prototype.pause=function(){this.audio.pause(),this.playing=!1},a.prototype.stop=function(){this.audio.pause(),this.audio.currentTime=0,this.playing=!1},a.prototype.next=function(t){t=t||{};var e=this._playlist.tracks.length;if(this._playlistIndex>=e-1){if(!t.loop)return;this._playlistIndex=-1}if(this._playlist&&e)return this.play({playlistIndex:++this._playlistIndex})},a.prototype.previous=function(){if(!(this._playlistIndex<=0))return this._playlist&&this._playlist.tracks.length?this.play({playlistIndex:--this._playlistIndex}):void 0},a.prototype.seek=function(t){if(!this.audio.readyState)return!1;var e=t.offsetX/t.target.offsetWidth||(t.layerX-t.target.offsetLeft)/t.target.offsetWidth;this.audio.currentTime=e*(this.audio.duration||0)},a.prototype.cleanData=function(){this._track=void 0,this._playlist=void 0},a.prototype.setVolume=function(t){this.audio.readyState&&(this.audio.volume=t)},a.prototype.setTime=function(t){this.audio.readyState&&(this.audio.currentTime=t)},e.exports=a},{}]},{},[1])(1)});

@@ -158,3 +158,7 @@ 'use strict';

if (length) {
this._playlistIndex = options.playlistIndex || 0;
if (options.playlistIndex === undefined) {
this._playlistIndex = this._playlistIndex || 0;
} else {
this._playlistIndex = options.playlistIndex;
}

@@ -186,3 +190,3 @@ // be silent if index is out of range

this.audio.play();
return this.audio.play();
};

@@ -201,11 +205,16 @@

SoundCloud.prototype.next = function () {
SoundCloud.prototype.next = function (options) {
options = options || {};
var tracksLength = this._playlist.tracks.length;
if (this._playlistIndex >= tracksLength - 1) {
return;
if (options.loop) {
this._playlistIndex = -1;
} else {
return;
}
}
if (this._playlist && tracksLength) {
this.play({playlistIndex: ++this._playlistIndex});
return this.play({playlistIndex: ++this._playlistIndex});
}

@@ -220,3 +229,3 @@ };

if (this._playlist && this._playlist.tracks.length) {
this.play({playlistIndex: --this._playlistIndex});
return this.play({playlistIndex: --this._playlistIndex});
}

@@ -223,0 +232,0 @@ };

{
"name": "soundcloud-audio",
"version": "1.2.2",
"version": "1.3.1",
"description": "Play SoundCloud tracks and playslists in modern browsers with HTML5 Audio API",

@@ -13,2 +13,3 @@ "main": "index.js",

"test": "./node_modules/karma/bin/karma start --single-run --browsers Chrome",
"test:watch": "./node_modules/karma/bin/karma start --auto-watch --browsers Chrome",
"lint": "eslint ./index.js --fix"

@@ -34,15 +35,15 @@ },

"devDependencies": {
"browserify": "^8.1.0",
"chai": "^3.3.0",
"eslint": "^4.8.0",
"jasmine-core": "^2.1.3",
"karma": "^0.12.31",
"browserify": "^16.1.0",
"chai": "^4.1.2",
"eslint": "^4.18.2",
"jasmine-core": "^3.1.0",
"karma": "^2.0.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.1.7",
"karma-mocha": "^0.2.0",
"mocha": "^2.3.3",
"uglify-js": "^2.4.16",
"watchify": "^2.2.1"
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"mocha": "^5.0.1",
"uglify-js": "^3.3.12",
"watchify": "^3.10.0"
},
"dependencies": {}
}

@@ -78,14 +78,16 @@ # <img src="http://www.officialpsds.com/images/thumbs/Soundcloud-Logo-psd47614.png" width="75" align="left">&nbsp;soundcloud-audio.js

#### `play([options])`
#### `play(options)`
Starts playing track if it's not playing right now. Accepts `options` object where all fields are completely optional:
Start playing track if it's not playing right now.
- `streamUrl` - any audio streaming url string (e.g. SoundCloud track's `stream_url`), if it's passed it will be the main playing source.
- `playlistIndex` - number that specifies the position of the track to play in resolved SoundCloud playlist's `tracks` array.
Returns a Promise and accepts `options` object:
- `options.streamUrl` - any audio streaming url string (e.g. SoundCloud track's `stream_url`), if it's passed it will be the main playing source.
- `options.playlistIndex` - number that specifies the position of the track to play in resolved SoundCloud playlist's `tracks` array.
#### `preload(streamUrl, preloadType)`
Preloads track data without playing it.
Preload track data without playing it.
- `preloadType` - This attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
- `preloadType` - this attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
* 'none': indicates that the audio should not be preloaded;

@@ -105,9 +107,13 @@ * 'metadata': indicates that only audio metadata (e.g. length) is fetched;

#### `next()`
#### `next(options)`
Skip to the next track in playlist to play.
Skip to the next track in playlist to play.
Returns a Promise and accepts `options` object:
- `options.loop` - boolean, if set to `true` will start at the beginning of a playlist after the last track.
#### `previous()`
Return to the previous track in playlist.
Return to the previous track in playlist (returns a Promise).

@@ -114,0 +120,0 @@ #### `seek(DOMEvent)`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc