Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions src/com/nokia/mid/sound/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
*/
package com.nokia.mid.sound;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;


public class Sound
{
public static final int FORMAT_TONE = 1;
Expand All @@ -24,25 +32,63 @@ public class Sound
public static final int SOUND_STOPPED = 1;
public static final int SOUND_UNINITIALIZED = 3;


public Sound(byte[] data, int type) { }
private Player player;

public Sound(byte[] data, int type)
{
try
{
if (type == FORMAT_TONE)
{
player = Manager.createPlayer(new ByteArrayInputStream(data), "audio/x-tone-seq");
}
else if (type == FORMAT_WAV)
{
player = Manager.createPlayer(new ByteArrayInputStream(data), "audio/wav");
}
}
catch (MediaException exception) { }
catch (IOException exception) { }
}

public Sound(int freq, long duration) { }


public static int getConcurrentSoundCount(int type) { return 1; }

public int getGain() { return 0; }

public int getState() { return 1; }
public int getState()
{
int state = player.getState();

switch (state)
{
case Player.STARTED:
return SOUND_PLAYING;
case Player.PREFETCHED:
case Player.REALIZED:
return SOUND_STOPPED;
case Player.UNREALIZED:
case Player.CLOSED:
default:
return SOUND_UNINITIALIZED;
}
}

public static int[] getSupportedFormats() { return new int[]{}; }

public void init(byte[] data, int type) { }
public void init(byte[] data, int type)
{
// init's functionality is covered when Manager creates the player - leave empty
}

public void init(int freq, long duration) { }

public void play(int loop) { }
public void play(int loop)
{
player.setLoopCount(loop);
player.start();
}

public void release() { }

Expand All @@ -52,6 +98,9 @@ public void setGain(int gain) { }

public void setSoundListener(SoundListener listener) { }

public void stop() { }
public void stop()
{
player.stop();
}

}
51 changes: 41 additions & 10 deletions src/org/recompile/mobile/PlatformPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ public PlatformPlayer(InputStream stream, String type)
{
player = new midiPlayer(stream);
}
else
else if (type.equalsIgnoreCase("audio/x-wav") || type.equalsIgnoreCase("audio/wav"))
{
if(type.equalsIgnoreCase("audio/x-wav") || type.equalsIgnoreCase("audio/wav"))
{
player = new wavPlayer(stream);
}
else /* TODO: Implement a player for amr and mpeg audio types */
{
System.out.println("No Player For: "+contentType);
player = new audioplayer();
}
player = new wavPlayer(stream);
}
else if (type.equalsIgnoreCase("audio/x-tone-seq"))
{
//
player = new tonePlayer(stream);
}
else /* TODO: Implement a player for amr and mpeg audio types */
{
System.out.println("No Player For: "+contentType);
player = new audioplayer();
}
}
controls[0] = new volumeControl();
Expand Down Expand Up @@ -342,6 +344,35 @@ public boolean isRunning()
}
}

/* Todo: Implement tone playing functionality */
private class tonePlayer extends audioplayer
{
private InputStream toneStream;
private int loops = 0;

public tonePlayer(InputStream stream) { toneStream = stream; }

public void start()
{
// Todo implement functionality to play a tone sequence
state = Player.STARTED;
}

public void stop()
{
// Todo implement functionality to stop playing a tone sequence
state = Player.PREFETCHED;
}

public void setLoopCount(int count) { if (count > -1) { loops = count; } }

public boolean isRunning()
{
// Todo implementation depends on start()
return false;
}
}

// Controls //

private class midiControl implements javax.microedition.media.control.MIDIControl
Expand Down