Programming for Mobiles - Practical 2

Disconnection tolerant media player

Programmatically creating a progress bar

If you create a ProgressBar in your code and add it to your activity then you will get an indeterminate spinner rather than a bar. In order to create a bar you need to set the style of the View when you create it:

  ProgressBar p = new ProgressBar(this, null,;

Splicing audio buffer

A suggested outline for your SplicingAudioBuffer is suggested below. This should be able to take decoded packets of bytes from multiple streams and play them once only in the correct order.

public class SplicingAudioBuffer {

	public SplicingAudioBuffer(int channels, int rate) {
			// create the AudioTrack and start playback

	public synchronized void write(long granulePosition, int packetNumber,
			byte[] data) {
		// if the data isPlayable then write it (fully) to the audio device

	public void close() {
		// stop and release the audio track

	private boolean isPlayable(long granulePosition, int packetCounter) {
		// return true if the bytes corresponding to this particular packet at this particular granuleposition have not been played already

Some previous emails which might be useful

1, 2, 3