MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / MMAPIPlayer

Class MMAPIPlayer

Ports/J2ME/src/com/codename1/impl/midp/MMAPIPlayer.java:49–293  ·  view source on GitHub ↗

Simple abstraction to the player API in MMAPI used by the MIDP and Blackberry ports. This class is public only because the blackberry port relies on it and is in a different package, it is not meant for general use and is an implementation detail subject to change! this class might be changed at an

Source from the content-addressed store, hash-verified

47 * @author Shai Almog
48 */
49public class MMAPIPlayer implements PlayerListener, Media {
50
51 private static int volume = -1;
52 private boolean deleted;
53 private int lastTime;
54 Player nativePlayer;
55 private InputStream sourceStream;
56 private Runnable onComplete;
57 private boolean disposeOnComplete = true;
58
59 private MMAPIPlayer(Player p) {
60 this.nativePlayer = p;
61 if (volume > -1) {
62 setVolume(volume);
63 } else {
64 setVolume(100);
65 }
66 }
67
68 public int getVolume() {
69 if (volume > -1) {
70 return volume;
71 }
72 try {
73 VolumeControl volc = (VolumeControl) nativePlayer.getControl("VolumeControl");
74 if (volc != null) {
75 return volc.getLevel();
76 }
77 } catch (Exception e) {
78 }
79 return -1;
80 }
81
82 public void setVolume(int v) {
83 volume = v;
84 try {
85 VolumeControl volc = (VolumeControl) nativePlayer.getControl("VolumeControl");
86 if (volc != null) {
87 volc.setLevel(v);
88 }
89 } catch (Exception e) {
90 }
91 }
92
93 /**
94 * @inheritDoc
95 */
96 public static MMAPIPlayer createPlayer(String uri, Runnable onCompletion) throws IOException {
97 try {
98 Player p = Manager.createPlayer((String) uri);
99 p.realize();
100 MMAPIPlayer m = new MMAPIPlayer(p);
101 m.bindPlayerCleanupOnComplete(p, null, onCompletion);
102 return m;
103 } catch (MediaException ex) {
104 ex.printStackTrace();
105 throw new IOException(ex.toString());
106 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected