[ 
https://issues.apache.org/jira/browse/CB-879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292691#comment-13292691
 ] 

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('"
 + this.id + "', "+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) {
                                        this.mPlayer.reset();
                                }
                                // 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: https://issues.apache.org/jira/browse/CB-879
>             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
> http://docs.phonegap.com/en/edge/cordova_media_media.md.html#media.play
> 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: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to