Music is not playing - Attempt to call getDuration without a valid mediaplayer

2,270 views
Skip to first unread message

Aritz Madariaga

unread,
May 31, 2012, 12:27:56 PM5/31/12
to phon...@googlegroups.com
Im trying to play a sound on my phonegap based app but im getting this error:

05-31 18:23:00.898: E/MediaPlayer(8984): error (1, -2147483648)
05-31 18:23:00.918: I/GATE(8984): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
05-31 18:23:00.923: E/MediaPlayer(8984): Error (1,-2147483648)
05-31 18:23:00.933: E/MediaPlayer(8984): error (1, -2147483648)
05-31 18:23:00.933: E/MediaPlayer(8984): Error (1,-2147483648)
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer
05-31 18:23:00.938: E/MediaPlayer(8984): error (-38, 0)
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer
05-31 18:23:00.938: E/MediaPlayer(8984): Error (-38,0)
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer

Simon MacDonald

unread,
May 31, 2012, 2:43:14 PM5/31/12
to phon...@googlegroups.com
Show your code.

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com

Aritz Madariaga

unread,
Jun 1, 2012, 6:34:23 AM6/1/12
to phon...@googlegroups.com
Im using lungo.js framework + phonegap

The framework sound js is this:
/**
 * Player audio files (.mp3, .wav and .ogg)
 *
 * @namespace LUNGO.Sugar
 * @class Sound
 *
 */

LUNGO.Sugar.Sound = (function(lng, undefined) {
    var _background = document.createElement('audio');
    var _sound = document.createElement('audio');

    /**
    * Plays music in background with automatic rewind.
    *
    * @method background
    *
    * @param  {string} Source of sound file
     */
    var background = function(source) {
        if (source) {
            _setSourceAndPlay(_background, source);
            _background.addEventListener('ended', function(){
                this.currentTime = 0;
            }, false);
        }
        else {
            _background.pause();
        }
    };

    /**
    * Play a given sound
    *
    * @method play
    *
    * @param  {string} Source of sound file
     */
    var play = function(source) {
        _setSourceAndPlay(_sound, source);
    };

    _setSourceAndPlay = function(container, source) {
        container.setAttribute('src', source);
        container.play();
    };

    return {
        background: background,
        play: play
    }
})(LUNGO);


The javascript code is:

Game.Sound = (function(lng, undefined) {

    var RESOURCES = {
        BACKGROUND: 'assets/audio/background.mp3',
        BUTTON: '',
        WIN: ''
    };

    var _active = true;

    toggle = function() {
        if (_active) {
            off();
        } else {
            on();
        }
    };

    on = function() {
        lng.Sugar.Sound.background(RESOURCES.BACKGROUND);
        _active = true;
        _visibility();
    };

    off = function() {
        lng.Sugar.Sound.background(null);
        _active = false;
        _visibility();
    };

    button = function() {
        _play(RESOURCES.BUTTON)
    };

    win = function() {
        _play(RESOURCES.WIN);
    };

    _play = function(resource) {
        if (_active) {
            lng.Sugar.Sound.play(resource);
        }
    };

    _visibility = function() {
        var el = lng.dom('a[data-control=sound]');
        if (_active) {
            el.removeClass('red').children('.icon').removeClass('bell-off').addClass('bell-on');
        } else {
            el.addClass('red').children('.icon').removeClass('bell-on').addClass('bell-off');
        }
    }

    return {
        on: on,
        off: off,
        toggle: toggle,
        button: button,
        win: win
    }

})(LUNGO);



El jueves, 31 de mayo de 2012 20:43:14 UTC+2, Simon escribió:
Show your code.
On Thu, May 31, 2012 at 12:27 PM, Aritz Madariaga <eife...@gmail.com> wrote:
Im trying to play a sound on my phonegap based app but im getting this error:

05-31 18:23:00.898: E/MediaPlayer(8984): error (1, -2147483648)
05-31 18:23:00.918: I/GATE(8984): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
05-31 18:23:00.923: E/MediaPlayer(8984): Error (1,-2147483648)
05-31 18:23:00.933: E/MediaPlayer(8984): error (1, -2147483648)
05-31 18:23:00.933: E/MediaPlayer(8984): Error (1,-2147483648)
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer
05-31 18:23:00.938: E/MediaPlayer(8984): error (-38, 0)
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer
05-31 18:23:00.938: E/MediaPlayer(8984): Error (-38,0)
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer
05-31 18:23:00.938: E/MediaPlayer(8984): Attempt to call getDuration without a valid mediaplayer

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to

Simon MacDonald

unread,
Jun 1, 2012, 8:44:10 AM6/1/12
to phon...@googlegroups.com
Right, you are not using the PhoneGap Media API to play your sound so this is not a PhoneGap problem. I've looked at Sugar.Sound and it uses "audio" tags to play audio. Unfortunately, audio tag support on the Android WebView is pretty poor. I've been trying to monkey patch it with my Corinthian project.

In the meantime you should stick with the Media API if you want to play a sound.

Simon Mac Donald
http://hi.im/simonmacdonald


Reply all
Reply to author
Forward
0 new messages