В начало!  
Сделай закладку этой страницы в Digg Сделай закладку этой страницы в Del.icoi.us Сделай закладку этой страницы в Slashdot Сделай закладку этой страницы в Technorati
arrow Технологии arrow Java ME arrow Микширование звука с помощью MMAPI


feed image


Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285

Warning: Division by zero in /home/sunadmin/developers.sun.ru/docs/mambots/content/geshibot/geshi.class.php on line 2285
Микширование звука с помощью MMAPI
Автор Vikram Goyal   
13.02.2009 г.

Mobile Media API (MMAPI) - это протоколо- и платформо-независимый API для проигрывания и работы с мультимедийным контентом на мобильных устройствах.


API предоставляет широкие возможности для работы с несколькими разными типами медиа, в зависимости от возможностей мобильного устройства. В этом примере мы покажем как воспользоваться MMAPI для микширования и проигрывания музыки.

Микширование: в чем проблема?

Возможность наложения звуков в приложениях для мобильных устройствах безусловно востребована - например, в играх. MMAPI позволяет этого добиться, но есть несколько подводных камней.

Фрагментация платформы

Реализации MMAPI, которые возвращают true в качестве значения системного свойства supports.mixing, теоретически, должны обеспечивать следующие возможности:

  • Поддерживать одновременное проигрывание минимум двух тоновых сигналов
  • Использовать Manager.playTone(), когда другой экземпляр проигрывателя воспроизводит звук
  • Поддерживать проигрывание на как минимум двух экземплярах плеера

На практике не все реализации MMAPI соблюдают эти требования. Это зависит от устройста и точный ответ о том, что возможно на вашем устройстве можно получить лишь в документации по этому устройству от его производителя.

Множественные экземпляры плеера

При использовании нескольких экземпляров плеера в одном приложении есть опасность, что на их обслуживание потребуется слишком много ресурсов. Когда плеер находится в состоянии предварительной загрузки или проигрывания, приходится хранить их в памяти длительное время, так как экземпляр плеера в таком состоянии может требовать эксклюзивного доступа к какому-нибудь системному ресурсу, например,  аудио-устройству и другие вынуждены ждать. Поэтому даже если устройство поддерживает несколько экземпляров плеера, мы рекомендуем этим не злоупотреблять.

MIDI, тональные звуки, и сэмплированное аудио

То, что можно микшировать зависит от возможностей вашего устройства. Большинство известных реализаций позволяют микшировать один экземпляр сэмплированного аудио и один экземпляр тонального звука или MIDI, или и то и другое.

Пишем код

Микширование звука - обычный прием в играх, где фоновая мелодия играет все время, а действия пользователя или события в приложения генерируют другие короткие звуки. В следующем примере на фоне сэмплтированной мелодии проигрываются MIDI и тональные звуки.

Пример создан и может быть запущен с помощью Netbeans 6.5. При создании приложения не забудьте отметить MMAPI среди дополнительных API, так как MIDIControl не входит в базовый MIDP 2.0 MMAPI.

Код протестирован с помощью Sun Wireless Toolkit 2.2, который входит в netbeans 6.5. Для запуска в других окружениях убедитесь, что MIDIControl поддерживается.

Ресурсы

  1. import javax.microedition.media.*;
  2. import javax.microedition.lcdui.*;
  3. import javax.microedition.midlet.*;
  4. import javax.microedition.media.control.MIDIControl;
  5.  
  6. /*
  7. * TechnicalTipMIDlet микширует мелодии, MIDI и тональные звуки
  8. * @author Vikram Goyal
  9. */
  10. public class TechnicalTipMIDlet extends MIDlet implements CommandListener {
  11.  
  12. //плееры для фоновой музыки и MIDI
  13. private Player backgroundMusic = null;
  14. private Player aPlayer = null;
  15.  
  16. // MIDIControl полученный из aPlayer
  17. private MIDIControl mControl = null;
  18.  
  19. private Display display = null;
  20. private Alert alert = null;
  21.  
  22. // команды для выхода из приложения, проигрывания MIDI (aCommand) и тонального звука (bCommand)
  23. private Command exitCommand = null;
  24. private Command aCommand = null;
  25. private Command bCommand = null;
  26.  
  27. public TechnicalTipMIDlet() {
  28. display = Display.getDisplay(this);
  29.  
  30. alert = new Alert("Message");
  31. alert.setString("Press A to play a tone, Press B to play a MIDI");
  32. alert.setTimeout(Alert.FOREVER);
  33.  
  34. //создаем комманды
  35. exitCommand = new Command("Exit", Command.EXIT, 1);
  36. aCommand = new Command("A", Command.ITEM, 1);
  37. bCommand = new Command("B", Command.ITEM, 1);
  38.  
  39. alert.addCommand(exitCommand);
  40. alert.addCommand(aCommand);
  41. alert.addCommand(bCommand);
  42.  
  43. //подписываемся на события
  44. alert.setCommandListener(this);
  45.  
  46. //инициализируем экземпляры плеера
  47. initialize();
  48. }
  49.  
  50. private void initialize() {
  51. //создаем и загружаем экземпляры плеера
  52. try {
  53.  
  54. // для фоновой музыки загружаем wav файл и проигрываем его в бесконечном цикле
  55. backgroundMusic = Manager.createPlayer(
  56. getClass().getResourceAsStream("music.wav"), "audio/x-wav");
  57. backgroundMusic.prefetch();
  58. backgroundMusic.setLoopCount(-1);
  59.  
  60. // создаем проигрыватель для MIDI, подгружаем звук
  61. aPlayer = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
  62. aPlayer.prefetch();
  63.  
  64. // запоминаем MIDIControl
  65. mControl =
  66. (MIDIControl)aPlayer.getControl(
  67. "javax.microedition.media.control.MIDIControl");
  68.  
  69. } catch(Exception ex) {
  70. handleError(ex);
  71. }
  72. }
  73.  
  74. public void commandAction(Command cmd, Displayable disp) {
  75.  
  76. if(cmd == exitCommand) {
  77. destroyApp(true);
  78. notifyDestroyed();
  79. return;
  80. }
  81.  
  82. try {
  83.  
  84. // if it's the aCommand
  85. if (cmd == aCommand) {
  86.  
  87. // проигрываем MIDI
  88. mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 100);
  89. }
  90.  
  91. if (cmd == bCommand) {
  92.  
  93. //для bCommand, проигрываем тоновый звук используя класс Manager
  94. Manager.playTone(61, 1000, 100);
  95. }
  96. } catch(Exception ex) {
  97. handleError(ex);
  98. }
  99. }
  100.  
  101. public void startApp() {
  102.  
  103. try {
  104.  
  105. // запускаем фоновую музыку
  106. if (backgroundMusic != null)
  107. backgroundMusic.start();
  108. else
  109. handleError(new Exception("Error with background player"));
  110. } catch(Exception ex) {
  111. handleError(ex);
  112. }
  113.  
  114. display.setCurrent(alert);
  115. }
  116.  
  117. public void pauseApp() {
  118. }
  119.  
  120. public void destroyApp(boolean unconditional) {
  121.  
  122. try {
  123.  
  124. //закрываем плееры
  125. if(backgroundMusic != null) {
  126. backgroundMusic.close();
  127. backgroundMusic = null;
  128. }
  129.  
  130. if(aPlayer != null) {
  131. aPlayer.close();
  132. aPlayer = null;
  133. }
  134.  
  135. } catch(Exception e) {
  136. handleError(e);
  137. }
  138.  
  139. }
  140.  
  141. private void handleError(Exception ex) {
  142. alert.setTitle("Error");
  143. alert.setString(ex.getMessage());
  144. display.setCurrent(alert);
  145. ex.printStackTrace();
  146. }
  147. }
  148.  
  149.  
 
 

Добавить комментарий


Защитный код
Обновить