facebook

How to use getCurrentPosition

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #345986 Reply

    Muhammad
    Member

    I found getCurrentPosition for audio like this in phoneui.js,
    can you give me example to use this function?

        MediaAudioImpl.prototype.getCurrentPosition = function(succ, err) {    
            succ(this._audio.currentTime);
        }

    My code is like this, but I didn’t get position value.

    
    verse_mp3 = AudioPlayerWidget.fromWidget('m1-index4-audio3-container');            verse_mp3.setMedia(mp3file);
                verse_mp3.play();
                
                var mediaTimer = null;
    
                if (mediaTimer == null) {
                    mediaTimer = setTimeout(function() {
                        // get my_media position
                        verse_mp3.getCurrentPosition(
                            // success callback
                            function(position) {
                                alert(position)
                                if (position > -1) {
                                    
                                    setAudioPosition((position) + " sec");
                                }
                            },
                            // error callback
                            function(e) {
                                console.log("Error getting pos=" + e);
                                setAudioPosition("Error: " + e);
                            }
                        );
                    }, 1000);
                }
    
    function setAudioPosition(position) {
        document.getElementById('audio_position').innerHTML = position + " sec";
    }
    #346006 Reply

    Brandon
    Member

    Which version of Mobione are you using?
    Is this for a webapp or a native app?
    If Im not mistaken I believe the getCurrectPosition is Phonegap based, so may not work in webapps.
    Also, if its is based on Phonegap make sure you are waiting for Phonegap to load all the way before calling it.

    #346057 Reply

    Muhammad
    Member

    Thank you for your replay.

    I use native and play in iPhone. And mobione version is 2.6.1.
    When I get position and duration from gplayer.js, everything is working well.

    From gplayer.js, I try to pull out position.toPrecision(3) and duration.toPrecision(3) value, And I got it

                    if (duration > 0) {
                        var perc = position * 100 / duration;
                        this.playBar.width((perc > 100 ? 100 : perc);
                        //$('#progressbar').progressbar({value: (perc > 100 ? 100 : perc)});
                        document.getElementById('progressbar_left_val').innerHTML = position.toPrecision(3) + " sec";
                        $('#progressbar').progressbar({value: perc });
                        document.getElementById('progressbar_right_val').innerHTML = duration.toPrecision(3) + " sec";
                        //setAudioPosition((perc > 100 ? 100 : perc));
                        
                        this.durationLabel.text(this.convertTime(duration));
                    } else if (position == 0) {

    Is it something wrong with my frist posting code?

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: How to use getCurrentPosition

You must be logged in to post in the forum log in