Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

intel/cordova-plugin-intel-xdk-player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DISCONTINUATION OF PROJECT.

This project will no longer be maintained by Intel.

Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.

Intel no longer accepts patches to this project.

If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. DISCONTINUATION OF PROJECT. This project will no longer be maintained by Intel. Intel will not provide or guarantee development of or support for this project, including but not limited to, maintenance, bug fixes, new releases or updates. Patches to this project are no longer accepted by Intel. In an effort to support the developer community, Intel has made this project available under the terms of the Apache License, Version 2. If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the community, please create your own fork of the project.

intel.xdk.player

For playing audio files.

Description

The player plugin is used to play media natively in applications. It is a useful alternative to the HTML5 <video> and <audio> tags.

Methods

Properties

  • audioInfo — Information about the currently playing audio file.

Events

Methods

clearAudioCurrentTimeWatch

Stop a timer process that was started by a call to watchAudioCurrentTime.

intel.xdk.player.clearAudioCurrentTimeWatch(watchID);

Platforms

  • Apple iOS
  • Google Android

Parameters

watchID: The watch identifier that was returned by a call to watchAudioCurrentTime.

Example

var watchID = intel.xdk.player.watchAudioCurrentTime(onSuccess, 3000);
// ...  some time later ...
intel.xdk.player.clearAudioCurrentTimeWatch(watchID);

loadSound

Preload a sound file.

intel.xdk.player.loadSound(soundURL, count);

Description

This method preloads a sound file so that it can be played without a delay when it is needed. The sound file must be included within the application file folder. Valid audio formats depend on the device that the app is running on.

Call this method when the application is not busy with other processes. For example, load sounds that will be needed at startup when the Cordova deviceready event fires. Then, while switching between levels of a game, unload sounds that are no longer needed and load new sounds.

Once a sound has been loaded, it can be played by calling playSound.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Parameters

  • soundURL: The URL of the sound file to play relative to the root folder of the application.
  • count: The polyphonic count of the sound — that is, how many instances of the sound can be playing simultaneously. This parameter is optional, and defaults to 1.

Events

Example

intel.xdk.player.loadSound("sounds/boing.wav",5);
intel.xdk.player.loadSound("sounds/jump.wav");

function loadSoundError()
{
    alert("Sound file could not be loaded");
}

document.addEventListener("intel.xdk.player.sound.error",loadSoundError,false);

playSound

Play a sound with no UI, events, or control.

intel.xdk.player.playSound(soundURL);

Description

This method will start playing a sound with no user control, no program control, and no events. (Compare startAudio.) It is intended as a simple way to play sound effects in your application. The sound file must be included within the application file folder. Valid audio formats depend on the device that the app is running on.

If the sound has been preloaded with loadSound, it will start playing immediately; otherwise, there may be a delay while it is loaded.

A call to playSound will be ignored if the number of occurrences of the specified sound that are already being played is greater than or equal to its polyphonic count. If the sound was not preloaded, its polyphonic count is 1.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Parameters

  • soundURL: The URL of the sound file to play relative to the root folder of the application.

Events

Example

// play the sound
intel.xdk.player.playSound("sounds/boing.wav");

setAudioCurrentTime

Change the current play position in an audio file.

intel.xdk.player.setAudioCurrentTime(time);

Description

This method causes the player to jump to the specified time in the currently playing audio file. If no audio file is currently playing, the effect of calling this method is undefined.

NOTE: This is an asynchronous operation. After a call to setAudioCurrentTime, watchAudioCurrentTime callbacks and the value of the player.audioInfo property are invalid until an audio.currenttime.set event occurs.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Parameters

  • time: A floating point value that specifies the time in seconds where the player should continue or where new audio files should start playing.

Events

Example

// Set Audio to start at 30 seconds into the file
intel.xdk.player.startAudio("sounds/file1.mp3",false);
intel.xdk.player.setAudioCurrentTime(30);

setAudioVolume

Change the volume at which an audio file is played.

intel.xdk.player.setAudioVolume(volume);

Description

This method causes the player volume to be changed.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Parameters

  • volume: A floating point value between 0.0 (muted) and 1.0 (maximum volume)..

Events

Example

// Set Audio to play at 75% volume.
intel.xdk.player.startAudio("sounds/file1.mp3",false);
intel.xdk.player.setAudioVolume(0.75);

startAudio

Play an audio file in the background.

intel.xdk.player.startAudio(audioURL, looping);

Description

This method will load and start playing a specified audio file without any UI, but with events and programmatic control. (Compare playSound.) It is useful for adding a response to an application event or for playing a background audio file while the user performs other actions.

If an audio file is already being played, then the current audio file will be stopped and the new one will be started.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Parameters

  • audioURL: The URL of the audio file to play relative to the root folder of the application.
  • looping:* A Boolean parameter specifying whether the audio should loop. Defaults to false.

Events

Example

// start playing an audio file without looping
intel.xdk.player.startAudio("sounds/cowbell.wav",false);

stopAudio

Stop playing an audio file.

intel.xdk.player.stopAudio();

Description

This method will stop the playing og an audio file previously created by a call to startAudio. If no audio file is currently playing, then a call to this method will not have any effect.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Events

Example

// stop playback of the audio
intel.xdk.player.stopAudio();

toggleAudio

Pause or resume playing an audio file.

intel.xdk.player.toggleAudio();

Description

  • If an audio file is currently playing, it will be paused.
  • If an audio file is currently paused, it will resume playing.
  • If there is no current audio either playing or paused, then this method will not have any effect.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Example

// toggle playback of the audio
intel.xdk.player.toggleAudio();

unloadAllSounds

Unload all sound files.

intel.xdk.player.unloadAllSounds();

Description

This method unloads unload all sound files that have been loaded with the loadSound or playSound methods. Unloading sound files will free up application memory.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Example

intel.xdk.player.unloadAllSounds();

unloadSound

Unload a sound file.

intel.xdk.player.unloadSound(soundURL);

Description

This method unloads a single a sound file. Unloading sound files will free up application memory.

Available Platforms

  • Apple iOS
  • Google Android
  • Microsoft Windows 8 - BETA
  • Microsoft Windows Phone 8 - BETA

Parameters

  • soundURL: The URL of the sound file to be unloaded relative to the root folder of the application.

Example

intel.xdk.player.unloadSound("sounds/boing.wav");

watchAudioCurrentTime

Start watching the time of the current audio file.

var watchID = intel.xdk.player.watchAudioCurrentTime(callback, interval);

Description

This method starts regularly updating the plugin’s audioInfo property. It can optionally specify a callback to be called with the audioInfo property as an argument at each update.

To cancel the watch, call clearAudioCurrentTimeWatch with the identifier returned by this method.

Platforms

  • Apple iOS
  • Google Android

Parameters

  • callback: A function that will be called at the specified time interval, with the plugin’s audioInfo property as an argument. May be nil.
  • interval: The time interval in milliseconds at which to update the audioInfo property and call the callback function.

Returns

Example

function onSuccess(info) {
    alert('Track Position: ' + info.currentTime + '\n' +
          'Track Duration: ' + info.duration + '\n');
}

// start a watch on the current audio track
var watchID = intel.xdk.player.watchAudioCurrentTime(onSuccess, 3000);

Properties

audioInfo

An object with the following properties describing the currently playing audio file. This property is only defined if watchAudioCurrentTime has been called, in which case it is updated regularly at the interval specified in the call.

  • currentTime: The current offset (in seconds) from the beginning of the currently playing audio file. Note that this property will temporarily be invalid following a call to setAudioCurrentTime.

  • duration: The length (in seconds) of the currently playing audio file.

Events

audio.currenttime.set

Execution of setAudioCurrentTime is complete.

Description

This event is fired when execution of setAudioCurrentTime is complete. It signifies that the watchAudioCurrentTime callback and the audioInfo variable are again valid.

audio.volume.set

Execution of setAudioVolume is complete.

Description

This event is fired when execution of setAudioVolume is complete

audio.error

An error occurred when trying to play an audio file.

Description

This event fires when there is an error in a call to startAudio.

audio.start

An audio file has started playing.

Description

This event is fired when the startAudio method successfully starts playing an audio file.

audio.stop

An audio file has finished playing or been stopped.

Description

This event will fire when an audio file that was played by a call to startAudio stops playing because it has reached the end or stopAudio was called.

sound.error

The file specified in the playSound command is invalid or missing.

Description

This event fires if the file specified in a call to playSound is invalid or missing.