Giter Club home page Giter Club logo

lempere / cordova-plugin-native-ringtones Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eltonfaust/cordova-plugin-native-ringtones

0.0 2.0 1.0 2.92 MB

Cordova Plugin for getting the native ringtone list on Android/IOS devices.You can also use this plugin to play native ringtones and custom ringtones(stored in the www folder).

Home Page: https://www.npmjs.com/package/cordova-plugin-native-ringtones

License: Apache License 2.0

JavaScript 85.18% CSS 14.46% HTML 0.06% Java 0.14% Objective-C 0.16%

cordova-plugin-native-ringtones's Introduction

This plugin is a fork of cordova-plugin-native-ringtones

cordova-plugin-native-ringtones-ef npm version

Plugin for the Cordova framework to get the native ringtone list.

The plugin helps get the native ringtones list on Android or IOS devices. And you can also use this plugin to play or stop the native ringtones and custom ringtones(added in the www folder).

Supported Platforms

  • iOS
  • Android

Installation

The plugin can be installed via Cordova-CLI and is publicly available on NPM.

Execute from the projects root folder:

$ cordova plugin add cordova-plugin-native-ringtones

Or install a specific version:

$ cordova plugin add cordova-plugin-native-ringtones-ef

Or install the latest head version:

$ cordova plugin add https://github.com/EltonFaust/cordova-plugin-native-ringtones

Usage

The plugin creates the object cordova.plugins.NativeRingtones and is accessible after the deviceready event has been fired.

You can call the function getRingtone to get the ringtone list. There are two/three parameters for this function:

  1. successCallback function: The cordova plugin will pass the ringtone list by the success object and the ringtone list is put in an array, each object in this array represent a ringtone (with name, url and category).
  2. errorCallback function: The function that will be called if the getRingtone failed.
  3. (just for Android) An string value to indicate the ringtone type. There are three kinds of ringtones for Android: 'notification', 'alarm', 'ringtone'. The default value is 'notification'.
document.addEventListener('deviceready', function () {
    cordova.plugins.NativeRingtones.getRingtone(
        function(ringtones) {
            //An object array contains all the ringtones
            console.log(ringtones);
        },
        function(err) {
            alert(err);
        }, 'alarm'
    );
}, false);

You can call the function playRingtone or stopRingtone to play or stop a ringtone by passing the URI of this ringtone. This plugin allow you to play both native ringtones and custom ringtones.

document.addEventListener('deviceready', function () {
    // if set to false, it will keep looping until call of stopRingtone (default: true)
    var playOnce = false;
    // ringtone volume, value between 0 and 100 (default: 100)
    var volume = 50;
    // Android only: play ringtone as type (default: cordova.plugins.NativeRingtones.STREAM_NOTIFICATION)
    var streamType = cordova.plugins.NativeRingtones.STREAM_ALARM;

    // params playOnce, volume, streamType are not required
    cordova.plugins.NativeRingtones.playRingtone(
        "/System/Library/Audio/UISounds/Modern/calendar_alert_chord.caf",
        playOnce, volume, streamType
    );

    window.setTimeout(function(){
        // if is set to false playOnce param for playRingtone method, call stopRingtone to stop playing
        cordova.plugins.NativeRingtones.stopRingtone();
    }, 5000);
}, false);

License

This software is released under the Apache 2.0 License.

cordova-plugin-native-ringtones's People

Contributors

eltonfaust avatar tongzhangzt avatar

Watchers

 avatar  avatar

Forkers

we-are-joinup

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.