Several problems of J2ME play sound (Nokia).

xiaoxiao2021-03-06  19

Nokia's mobile phone does not seem to be very good for sound playback. According to the experience of J2ME, this article summarizes the sound playback method of the three models of NOKIA.

1. NOKIA S40 (7210, 3300) and S60 (3650, 7650) / * These four machines do not support MIDP2.0 Media. I only have a model that I have done, and other models have no real machine test. I don't know if I support Media * / in MIDP2.0.

Import com.nokia.mid.sound. *;

Public class myclass extends canvas {... private sound ksound = null; private byte [] datakill = {(byte) 0x02, (byte) 0x4a, (byte) 0x3a, (byte) 0x404, (byte) 0x00 (byte) 0x0b, (byte) 0x28, (byte) 0x83, (byte) 0x28, (byte) 0x28, (byte) 0x2, (Byte) 0x28, (byte) 0x00};

PRIVATE FUN () {

IF (ksound! = null) {ksound.stop (); ksound = null;} ksound = new sound (datakill, snound.format_tone); ksound.setgain (255); // Set the volume ksound.play (1); / / Play, loop once}} // end myclass.

/ * Note: 1. How to get DataKill data. First, there must be a MIDI sound file; second, Nekia_Developers_suite_for_j2me is required. Use the Audio Converter in this tool to convert the MIDI file into byte data. Then put the found Dongdong COPY into your code.

2. About WTK how to use NOKIA's lib. Class.zip is found in the NOKIA development tool directory.. Open, find Sound.class, decompression, you should get com / nokia / ui / snound / snound.class, then package the entire directory into a zip file, put it under the liblies of your project. Ok. Or directly, the Class.zip is directly directly to LiB. After using WTK to compile the Package, open your JAR file, remove the COM folder containing Sound.class, and finalize JAR-size in JAD to change according to the actual situation. OK. Anyway, I am doing this, it is very troublesome. But I really don't want to use JBuilder. I don't know if there is a simple way. * /

2. NOKIA 7610 / * This model supports MIDP2.0 * /

Import javax.microedition.media. *;

Public class myclass extends canvas ... {private player player = null;

... private void fun () {... Plays ("kill.mid"); // call play function / * For WTK2.1, kill.mid files in the resideic * /} protected void Plays (String Source) {// Create a player try {if (player! = null) {Player.close (); player = null;} player = manager.createplayer (GetClass (). getresourceASstream ("/" / " source)," Audio / MIDI "); Player.AddPlayerListener (this); Player.setLoopCount (1); Player.Realize (); Player.Start ();} catCH (Exception PE) {pe.printstacktrace ();}} public void Playerupdate final Player p, final String event, final Object eventData) {// queue a call to updateEvent in the user interface event queue Display display = Display.getDisplay (myColorBall); display.callSerially (new Runnable () {public void run () {UPDATEEVENT (P, Event, EventData); }});} Private Void UpdateEvent (Player P, String Event, Object EventData) {if (Event == End_Of_Media) {p.close ();} else if (Event == Closed) {P = null;}}} // end myclass. ============================================== ====== / * Talk about another problem. When switching out the program, the game sound still continues to play a solution. * /// myclass Add a function void stoptone () {if (ksound! = Null) {ksound.stop ();}}

转载请注明原文地址:https://www.9cbs.com/read-41155.html

New Post(0)