GithubHelp home page GithubHelp logo

etiennea / phonegap-plugin-mediaplayer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 2.0 86 KB

Phonegap native audio player that supports queues for iOS only for now

License: Apache License 2.0

JavaScript 38.90% Objective-C 61.10%

phonegap-plugin-mediaplayer's Introduction

EXAMPLE ๐Ÿ‘‰

Cordova Audio Player Plug-in

Cordova plugin to stream remote audio data.

Plugin's Purpose

This cordova plug-in provides the ability to queue remote urls and create playlists. To gauge a songs media penetration it's possible to track the amount of network calls from an apps instance.

Overview

  1. Supported Platforms
  2. Installation
  3. ChangeLog
  4. Usage

Supported Platforms

  • iOS (including iOS8)

Installation

The plugin can either be installed from git repository, from local file system through the Command-line Interface.

Local development environment

From master:

# ~~ from master branch ~~
cordova plugin add https://github.com/katzer/phonegap-plugin-mediaplayer.git

from a local folder:

# ~~ local folder ~~
cordova plugin add cordova-plugin-audioplayer --searchpath path

To remove the plug-in, run the following command:

cordova plugin rm cordova-plugin-audioplayer

ChangeLog

Version 1.0.0dev (02.12.2016)

  • queue Tracks
  • start playing the queue
  • pause/resume playing the queue
  • clear the queue
  • fade in/out
  • register callbacks on playback events

Known issues

Usage

The plugin creates the object cordova.plugins.audioPlayer with the following methods:

  1. audioPlayer.play
  2. audioPlayer.queue
  3. audioPlayer.pause
  4. audioPlayer.resume
  5. audioPlayer.stop
  6. audioPlayer.playNext
  7. audioPlayer.setup
  8. audioPlayer.fadeInVolume
  9. audioPlayer.fadeOutVolume
  10. audioPlayer.getCurrentTrack

Plugin initialization

The plugin and its methods are not available before the deviceready event has been fired.

document.addEventListener('deviceready', function () {
    // cordova.plugins.audioPlayer is now available
}, false);

Play a song

Initialize a new queue, append a song object to it and start palying.

var song = {
    id: '22',
    title: 'California Lullabye',
    album: 'The Beautiful Machine',
    artist: 'Josh Woodward',
    file: 'https://www.joshwoodward.com/mp3/JoshWoodward-TheBeautifulMachine-01-CaliforniaLullabye.mp3',
    cover: 'https://upload.wikimedia.org/wikipedia/en/5/54/Public_image_ltd_album_cover.jpg'
}

var callbackFunc = function() {
    console.log('Song started');
}

cordova.plugins.audioPlayer.play(song, callbackFunc);

Queue a song

Append one ore more song objects to the existing queue (Initialize a new one if there is none). It's possible to replace the existing playlist by setting the replace flag to true. If play is set to true the playback is started on appending the track.

var song1 = {
    id: '22',
    title: 'California Lullabye',
    album: 'The Beautiful Machine',
    artist: 'Josh Woodward',
    file: 'https://www.joshwoodward.com/mp3/JoshWoodward-TheBeautifulMachine-01-CaliforniaLullabye.mp3',
    cover: 'https://upload.wikimedia.org/wikipedia/en/5/54/Public_image_ltd_album_cover.jpg'
}
var song2 = {
    id: '11',
    title: 'Let it in',
    album: 'Ashes',
    artist: 'Josh Woodward',
    file: 'https://www.joshwoodward.com/mp3/Ashes/JoshWoodward-Ashes-01-LetItIn.mp3',
    cover: 'https://upload.wikimedia.org/wikipedia/en/5/54/Public_image_ltd_album_cover.jpg'
}

var callbackFunc = function() {
    console.log('Song started');
}

var failureCallback = function(reason) {
    console.log('Error:' + reason);
}

var options = {
    replace: false, 
    play: false,
};

cordova.plugins.audioPlayer.queue([song1, song2], options, callbackFunc, failureCallback);

Pause playback

Pause playback.

var callback = function() {
    console.log('Song paused');
};
cordova.plugins.audioPlayer.pause(callback);

Resume playback

Resume playback after pause.

var callback = function() {
    console.log('Playback resumed');
};
cordova.plugins.audioPlayer.resume(callback);

Stop playback and clear playlist

Stop playing and clears the actual queue.

var callback = function() {
    console.log('Playback stopped');
};
cordova.plugins.audioPlayer.stop(callback);

Skip a track

Got to the next track.

var callback = function() {
    console.log('Skiped track');
};
cordova.plugins.audioPlayer.playNext(callback);

Set a trackingUrl

Set a trackingUrl.

var url = 'www.an-example-url.com/this/one/is/invalid';
var successCallback = function() {
    console.log('Url succesfully added');
};
var failureCallback = function() {
    console.log('Some error occured');
};
cordova.plugins.audioPlayer.setup(url, successCallback, failureCallback);

Fade out volume

Fade the volume out.

var callback = function() {
    console.log('muted');
};
cordova.plugins.audioPlayer.fadeOutVolume(callback);

Fade in volume

Fade in the volume.

var callback = function() {
    console.log('faded in volume');
};
cordova.plugins.audioPlayer.fadeInVolume(callback);

Get currently played track

Get information about the currently played track.

var callback = function(id) {
    console.log('Song ' + id + 'is played.');
};
cordova.plugins.audioPlayer.getCurrentTrack(callback);

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

This software is released under the Apache 2.0 License.

ยฉ 2013-2016 appPlant GmbH, All rights reserved

phonegap-plugin-mediaplayer's People

Contributors

etiennea avatar katzer avatar pknittel avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

katzer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.