DEADSOFTWARE

Fix memory corruption when load library
[mp3cc.git] / mps / src / P.java
1 /*
2 * The player class used for playing the music.
3 * */
5 import javax.microedition.media.*;
7 public class P
8 {
9 public static Player p = null;
11 /* load music player */
12 public static int a(String resource, String type)
13 {
14 try
15 {
16 if (p != null)
17 {
18 p.close();
19 }
20 p = Manager.createPlayer(FW.fw.getClass().getResourceAsStream(resource), type);
21 p.realize();
22 p.prefetch();
23 }
24 catch (Exception e)
25 {
26 return 0;
27 }
29 return -1;
30 }
32 /* play */
33 public static int a()
34 {
35 try
36 {
37 if (p == null)
38 return 0;
40 p.start();
41 }
42 catch (Exception e)
43 {
44 return 0;
45 }
47 return -1;
48 }
50 /* stops playing the music */
51 public static void b()
52 {
53 try
54 {
55 if (p != null)
56 {
57 p.stop();
58 }
59 }
60 catch (Exception e)
61 {}
62 }
64 /* set loop count, -1 indefinitely */
65 public static int a(int x)
66 {
67 try
68 {
69 if (p != null)
70 {
71 if (p.getState() == Player.STARTED)
72 return 0;
73 p.setLoopCount(x);
74 return -1;
75 }
77 } catch (Exception e)
78 {
79 return 0;
80 }
81 return 0;
82 }
84 /* get duration time in milliseconds */
85 public static int c()
86 {
87 try
88 {
89 if (p != null)
90 {
91 return (int)(p.getDuration() / 1000);
92 }
93 else return -1;
94 }
95 catch (Exception e)
96 {
97 return -1;
98 }
99 }