incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominik (JIRA)" <>
Subject [jira] [Commented] (CB-879) Support to set the volume when playing short sounds
Date Mon, 11 Jun 2012 08:47:42 GMT


Dominik commented on CB-879:

I think calling setVolume() on Android doesn't work in this case because it cannot be called
prior to playing the sound. This is because the MediaPlayer instance is created in startPlaying()
(see last line in code fragment below, taken from 1.7)

public void startPlaying(String file, float volume) {
		if (this.recorder != null) {
		    Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" +
+ "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
		// If this is a new request to play audio, or stopped
		else if ((this.mPlayer == null) || (this.state == MEDIA_STOPPED)) {
			try {
				// If stopped, then reset player
				if (this.mPlayer != null) {
				// Otherwise, create a new one
				else {
					this.mPlayer = new MediaPlayer();

and a call to

 public void setVolume(float volume) {
        this.mPlayer.setVolume(volume, volume);

will fail if mPlayer is not created yet.

We can call setVolume() right after startPlaying() but this would mean that the sound starts
to play with the default volume (in my case it has already finished playing once the volume
is set).
> Support to set the volume when playing short sounds
> ---------------------------------------------------
>                 Key: CB-879
>                 URL:
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Bada, CordovaJS, Docs, iOS, mobile-spec, webOS, WP7
>    Affects Versions: 1.7.0, 1.8.0
>            Reporter: Dominik
>            Assignee: Shazron Abdullah
>             Fix For: 1.9.0
> Looking at
> it seems like PhoneGap doesn't allow to set the volume when we play audio files (in order
that it is set prior to when the playing actually starts). In my case I would like to pass
the volume as a parameter to this method here:
> function playAudio(url)
> in order to play a short beep.
> I looked at the PhoneGap implementation for Android and iOS and it seems to be easy to
implement on these two platforms.
> Would it make sense to add support for this?

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message