Skip to content

Commit

Permalink
media: Overhaul PlatformPlayer in its entirety.
Browse files Browse the repository at this point in the history
This is a big one... in brief: Rework the entirety of PlatformPlayer,
and its surrounding classes to fix a bunch of stuff at once.

In detail:

VolumeControl, TempoControl, and ToneControl are implemented,
although only VolumeControl was truly tested, couldn't find a jar
that uses either ToneControl or TempoControl yet.

midiControl is partially implemented, but given how non-standard
most of it is, maybe it's rarely used, or whenever it's used,there's
a fallback for platforms that don't implement it.

mediaCache was temporarily disabled, as it will have to influence
the player's state handling, and i wanted the reference rewrite
to be as correct as possible in regards to the docs and other J2ME
simulators.

Some duplicate files like ToneControl and VolumeControl were removed
from microedition.media, as they're already present in
microedition.media.control, which is where they're actually loaded
from.

Player state handling was completely overhauled to match the official
J2ME Player docs, with listeners for END_OF_MEDIA events being added
for better conformance as they weren't present before. Most of this
housekeeping is relegated to the audioplayer superclass, with actual
functionality being handled by the underlying players, such as
wavPlayer and midiPlayer.

Player creation no longer makes it go from UNREALIZED straight to
PREFETCHED. We must follow the standard lifecycle of
UNREALIZED->REALIZED->PREFETCHED, and handle each accordingly, which
means that all players now have their setup be handled by their
realize() and prefetch() calls.

Add print messages on most of the critical functions, as we might
have problems on them (especially on what was just implemented)

Also, set everything up for the future TonePlayer.
  • Loading branch information
AShiningRay committed Oct 19, 2024
1 parent 286b7ae commit 8e93118
Show file tree
Hide file tree
Showing 5 changed files with 641 additions and 208 deletions.
10 changes: 8 additions & 2 deletions src/javax/microedition/media/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public static Player createPlayer(InputStream stream, String type) throws IOExce
streamCopy.writeTo(outStream);
}

// return checkMediaCache(streamMD5, stream, type);

return new PlatformPlayer(stream, type);
}

private static Player checkMediaCache(String streamMD5, InputStream stream, String type)
{
/* If we currently have this stream's player cached, return it instantly to avoid creating a new player and its overhead */
if (mediaCache.containsKey(streamMD5))
{
Expand All @@ -104,9 +111,8 @@ public static Player createPlayer(InputStream stream, String type) throws IOExce
* 2 - Setting the media playback time back to the start.
* 3 - Setting its state to PREFETCHED for good measure.
*/
mediaPlayers[mediaCache.get(streamMD5)].stop();
mediaPlayers[mediaCache.get(streamMD5)].cacheDeallocate();
mediaPlayers[mediaCache.get(streamMD5)].setMediaTime(0);
mediaPlayers[mediaCache.get(streamMD5)].prefetch();
return mediaPlayers[mediaCache.get(streamMD5)];
}

Expand Down
37 changes: 0 additions & 37 deletions src/javax/microedition/media/ToneControl.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/javax/microedition/media/VolumeControl.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/javax/microedition/media/control/ToneControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public interface ToneControl extends javax.microedition.media.Control
public static final byte TEMPO = -3;
public static final byte VERSION = -2;

public void setSequence(byte[] sequence);

}
Loading

1 comment on commit 8e93118

@vadosnaprimer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incredible job!!!

couldn't find a jar that uses either ToneControl or TempoControl yet

The author of https://github.com/maholator/MahoLator says such games don't exist, and even that no devices implement it!

Please sign in to comment.