Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
feed-media-audio-player
Advanced tools
Streaming audio client library for use in conjunction with Feed.fm
The Feed Media SDK for Javascript allows you to play DMCA compliant radio within your browser.
You can read more about the Feed Media API at https://feed.fm/. This library includes
a Feed.Player
class, which offers a simple interface starting and stopping audio
playback, and Feed.PlayerView
, which offers a simple way to render a music player in HTML.
This javascript library makes use of the Audio
element and works with desktop browsers
that support it: Edge 80+, Firefox 76+, Chrome 79+, and Safari 11.1+.
NOTE - we do NOT support mobile web browsers using our Javascript SDK. While the Javascript SDK may have some success on mobile web browsers, we do not officially support these mobile web integrations. To create the best user experience, we recommend understanding these limitations prior to developing on mobile web.In general, Feed.fm best practices discourage the use of our Javascript SDK on mobile web to ensure the applications you develop are optimized for the best possible user experience. We recommend building native mobile applications which can utilize our iOS SDK and Android SDK.
This library will work with the default demo credentials built into it, but you will need to get a set of production credentials from your contact at Feed.fm.
For bug reporting or questions, please send an email to support@feed.fm.
Install via npm:
npm install feed-media-audio-player
The dist/feed-media-audio-player.min.js
file in this package is suitable for including
directly in an HTML page. This is a self-executing function that exposes a Feed
variable
to your javascript. The file has no external dependencies.
Alternatively, if you're using a bundler, add the following to your code:
var Feed = require('feed-media-audio-player');
or
import Feed from 'feed-media-audio-player';
Bundler will automatically pull in dependent libraries.
To create a simple player and work with the Player
and PlayerView
objects,
create a web page with the following content
(or start with this jsbin):
<div id="player-view-div">
<div class='status'></div>
<button class="play-button">play</button>
<button class="pause-button">pause</button>
<button class="skip-button">skip</button>
</div>
<script src="feed-media-audio-player.min.js"></script>
<script>
var player = new Feed.Player('demo', 'demo');
// Display all the events the player triggers
player.on('all', function(event) {
console.log('player triggered event \'' + event + '\' with arguments:', Array.prototype.splice.call(arguments, 1));
});
var playerView = new Feed.PlayerView('player-view-div', player);
player.tune();
</script>
When the page is run, the user will be able to start and stop music playback, and skip songs. The control buttons enable and disable themselves based on the state of the player.
The Feed.Player class retrieves music from the Feed.fm servers and
sends them to the browser for playback. The methods on instances
of this class are mostly asynchronous, and events (that can be
subscribed to with simple on()
and off()
methods) indicate
player activity.
The class requires a token and secret in order to create an instance of the player:
var player = new Feed.Player('token', 'secret' /*, options */);
The final argument is optional and lets you specify some extra parameters to for the player (fully documented here).
Construction of the Player
instance kicks off communication with the feed.fm servers
to determine what music is available to the client. The player should not be
used until either a 'not-in-us' event or a 'stations' event is triggered, to
indicate that no music is available to the user or to indicate which music stations
can be tuned to.
The basic methods for use on the object are play()
, pause()
, stop()
and
skip()
, which do what you might expect.
You can adjust and retrieve music volume via getVolume()
and setVolume(X)
(where X
is
0..100) on the Player
instance.
Due to auto-play restrictions on browsers, and especially Mobile Safari,
the first call to play()
on the player object must be made in a user-initiated
event handler. If you don't want to immediately play music on the user event, you
can call initializeAudio()
in the event handler, and then play()
at a later
time. Repeated calls to initializeAudio()
are fine.
The player emits named events that you can attach to in order to
follow the state of the player. To follow an event, use the on(event, callback, context)
method, and to stop following an event use the off(event)
method.
Event handling comes from the BackBone.js project. Some example usage:
// simple callback
player.on('play-completed', function() { console.log('a play completed!'); });
// third argument sets 'this' for callback function
player.on('play-started', handler.someFunction, handler);
// passing 'all' as the event will cause all events to be sent to this callback
player.on('all', function(event) { console.log('received: ', event); });
// turn off all handlers for this event
player.off('play-completed');
// turn off a specific handler for this event
player.off('play-started', handler.someFunction);
The player emits the following events:
Player
instance, so register for this event early!skip()
to skip the current song, but the
server denied it (due to skip restrctions), then this event will be emitted.In addition to responding to events, the current state of the player
can be queried with getCurrentState()
. That call will return one of the
following strings:
A station
object looks like the following:
{
id: "276510",
name: "90BPM",
on_demand: 0,
pre_gain: 11.32,
options: {
id: "90BPM"
},
last_updated: "2019-04-05T21:49:08.000Z"
}
Some important points:
id
will change between different sessions - and should not
be used, for instance, to remember a user's favorite station. Instead, you should
use the station's name or a value in the options
object.options
object can be any arbitrary JSON object that you provide to feed.fm.
We suggest you use this for storing foreign keys or values that you wish to use
to search for particular stations. Some examples: storing a 'genre' or your own 'id'
or numeric BPM range.last_updated
refers to the last time the contents of a station with this name
were updated.A play
object looks like the following:
{
"id":"132459570",
"station": {
"id":"727",
"name":"Pretty Lights Music"
},
"audio_file": {
"id":"8707",
"duration_in_seconds":349,
"track": {
"id":"15226435",
"title":"Starve the Ego, Feed the Soul"
},
"release": {
"id":"1550367",
"title":"Drink the Sea"
},
"artist": {
"id":"1176632",
"name":"The Glitch Mob"
}
}
}
Feed.PlayerView should be given the ID of an element in the page and a reference to a Feed.Player instance, and it will update child elements based on player events and listen to user clicks to tell the Feed.Player to pause/play/skip. Child elements are identified by their class name and are used as described below:
The sample jsbin has a function to display in the javascript console all the events that the player emits.
When creating your own player skin, most everything can be stylized without having to edit javascript. For most projects, you should be able to fully customize the player using only CSS rules that take into account the 'button-enabled' and 'button-disabled' classes, along with the state of the player that is attached as a class to the top level HTML element of the player.
FAQs
Streaming audio client library for use in conjunction with Feed.fm
We found that feed-media-audio-player demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.