Computer Laboratory

Course material 2010–11

Programming for Mobiles

Practical 2: Disconnection tolerant media player

worksheet PDF


  • Wikipedia description of the Ogg Container Format [html]
  • Wikipedia description of the Vorbis Audio Codec [html]
  • Zip file containing example code which may be used as a starting point [zip]
  • Jar file containing a version of JOgg (an LGPL Java Vorbis decoder - among other things): [jar]
  • Jar file containing the PushOggDecoder implementation [jar] [javadoc]
  • Programmatically creating a progress bar [below]
  • Splicing audio buffer [below]

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