Code example for MediaController.MediaPlayerControl

Methods: getBufferPercentage, getCurrentPosition, getDuration, isPlaying

0
            switch (msg.what) { 
                case SHOW_PROGRESS: 
                    pos = setProgress(); 
//                    Log.d(TAG, "received: playing=" + videoControl.isPlaying()); 
                     
                    if (!dragging && videoControl.isPlaying()) { 
                        msg = obtainMessage(SHOW_PROGRESS); 
                        // always at the start of next second 
                        sendMessageDelayed(msg, ONE_SECOND - (pos % PROGRESS_PRECISION)); 
                    } 
                    break; 
            } 
        } 
    }; 
     
 
    private String stringForTime(int timeMs) {
        int totalSeconds = timeMs / 1000;
 
        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours   = totalSeconds / 3600;
 
        if (hours > 0) {
            return String.format("%d:%02d:%02d", hours, minutes, seconds);
        } else { 
            return String.format("%02d:%02d", minutes, seconds);
        } 
    } 
 
    private OnSeekBarChangeListener seekListener = new OnSeekBarChangeListener() {
        long duration; 
        public void onStartTrackingTouch(SeekBar bar) { 
            duration = videoControl.getDuration(); 
        } 
        public void onProgressChanged(SeekBar bar, int progress, boolean fromtouch) { 
        	 
            if (fromtouch) { 
            	Log.d(TAG, "onProgressChanged started: progress=" + paths.get(playIndex)+ progress + "; tounch=" + fromtouch) ; 
                dragging = true; 
                duration = videoControl.getDuration(); 
                long newposition = (duration * progress) / 1000L; 
                videoControl.seekTo( (int) newposition); 
                if (currentTime != null) 
                    currentTime.setText(stringForTime( (int) newposition)); 
                 
                dragging = false; 
                Log.d(TAG, "onProgressChanged ended") ; 
            } 
        } 
        public void onStopTrackingTouch(SeekBar bar) { 
            dragging = false; 
            setProgress(); 
            togglePause(); 
        } 
    }; 
 
     
    private int setProgress() { 
        if (videoControl==null || dragging) {
            return 0; 
        } 
        int position = videoControl.getCurrentPosition();
        int duration = videoControl.getDuration();
        if (progress!= null) {
            if (duration > 0) {
                // use long to avoid overflow 
                long pos = 1000L * position / duration;
                progress.setProgress( (int) pos);
            } 
            int percent = videoControl.getBufferPercentage();
            progress.setSecondaryProgress(percent * 10);
        } 
 
        if (totalTime != null)
            totalTime.setText(stringForTime(duration));