Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Titanium Media Audio Player, progressBar get length music

$
0
0

how to get the length of the music and display the text on progressBar msg.

this is my practice i try to get from network, how should i do on Action listener on audioPlayer to get the audio length and show on progress bar when music is play

Appreciate if helping i'm new abt the titanium

exports.win2=function(ID){
 
    var win = Ti.UI.createWindow({
        title:'Media Play'
        });
 
    win.addEventListener('open',function(e){
        var client = Ti.Network.createHTTPClient({
        onload:function(e){
            var jsonString = JSON.parse(this.responseText);
 
            var label =Ti.UI.createLabel({
                text:jsonString.author, top:10
            });
 
            var btnPlay = Ti.UI.createButton({
                title:'Play',
                bottom:10,
                right:10    
            });
 
            var btnStop = Ti.UI.createButton({
                title:'Stop',
                bottom:10,
                right:120
            });
 
            var btnPause = Ti.UI.createButton({
                title:'Pause',
                left:10,
                bottom:10
            });
 
            var progressBar = Ti.UI.createProgressBar({
                width:250,
                min:0,
                max:10,
                value:0,
                color:'#fff',
                message:'Playing 0 of 10',
                font:{fontSize:14, fontWeight:'bold'},
            });
 
 
 
            var audioPlayer = Ti.Media.createAudioPlayer({
                url:jsonString.media_file
            });
 
            audioPlayer.addEventListener('progress',function(e){
                // progressBar.max = stream.duration;
                // progressBar.value = parseInt(MediaPlayer.progress/1000,10);
                 var progressValue = ((Math.round(e.progress))/1000)/60;
                 progressBar.value = progressValue;
                // Ti.API.info('value is '+ progressValue);
                 //progressBar.setValue(progressBar.getValue()+1);
                 progressBar.value = parseInt(MediaPlayer.currentPlaybackTime/1000,10);
            });
 
            win.add(progressBar);
            progressBar.show();
            win.add(btnPause);
            win.add(label);
            win.add(btnPlay);
            win.add(btnStop);
 
            btnPlay.addEventListener('click',function(){
                //if(audioPlayer.pause){
                    audioPlayer.start();
                //}
            });
 
            btnStop.addEventListener('click',function(){
 
                    audioPlayer.stop();
            });
 
            btnPause.addEventListener('click',function(){
 
                     audioPlayer.pause();
            });
        },
        onerror:function(e){
            alert('Connection Lost');   
        },
        timeout:20000
    });
 
    client.open('GET','http://gallery.mobile9.com/f/'+ ID +'/?view=json');
    client.send();
    win.activity.actionBar.setDisplayHomeAsUp(true);
         win.activity.actionBar.onHomeIconItemSelected = function () { 
            if (Ti.Platform.osname === 'android')
                { 
                    audioPlayer.release();
                }
         win.close();
        };  
    });
    return win;     
};

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>