Monday, August 30, 2010

Zekr Audio Support

Zekr used a flash player for recitation playback
until version 0.7.5 beta 1.
Three years ago, Zekr 0.6.5 was released (code named Zekr Ramadan Edition, ZRE), in which we first introduced audio playback support. We used a tricky way of playing mp3 files, which was to have a flash script play audio, and controlled via JavaScript methods and callbacks. This method of playing was not easy to implement and we had to do a lot of hacks to have it work. For example, instead of loading page HTMLs from file://, we had to load it through http://. Otherwise, flash security prevents JavaScript intraction between Zekr and the player. As a result we integrated an embedded HTTP server (based on NanoHTTPD), which was there until Zekr 0.7.5 beta 1, in which we completely redesigned audio playback system.

Although integrating with a flash player was done, we had many issues with flash plugin in Linux, Mac and even Windows. Flash was a non-free package in Linux and it wasn't included in recent Linux distributions. Moreover we have other restrictions with flash player. We were
  1. not able to continue playing when end of a page was reached;
  2. not able to play an aya (verse) twice or more;
  3. not able to wait between consequent playbacks;
plus many other issues, from crashing to not being able to display Quran page due to the local HTTP server used in some situations (because of proxy settings). Add to the above issues that Zekr was not a completely free software because it included a mp3 player .swf file which was a non-free content. As a result we switched to a pure Java mechanism to handle audio files. By doing this, we had the following advantages:
  1. being able to continue playing in a special scope (sura, juz, continuous, etc.);
  2. being able to play an aya (verse) twice or more;
  3. being able to wait constant seconds between two consequent ayas;
  4. being able to play formats other than mp3: speex, ogg, wav, au, etc.;
  5. no more dependency to an embedded HTTP server;
  6. being able to control audio playback functions such as play/pause/stop, next/prev, seek forward/backward, volume up/down, by keyboard shortcuts.
  7. being able to play special items: Audhubillah, Bismillah and Sadaghallah
We gradually enhanced our recitation support up to Zekr 0.7.5: made recitation file format simpler, added shortcut key support, added different playing modes for special items, added playing scope, made installing offline recitations easier.

With the new audio player mode, although Zekr recitation support was meaningfully improved, there are some problems for our Linux and Mac. On Mac, Zekr cannot be closed if audio player is used (and should be forcefully closed). On Linux, although it works perfectly (related bug report), it's not very easy to have it work for a Linux newbie. Zekr audio player only works with Sun Java, but as it's not a completely free package, modern distributions do not include it by default. For example Ubuntu 10.04, only includes OpenJDK (which is a free implementation of Java, with a large portion of Sun's plus some re-coding) in standard repositories, and allow Sun Java only as a second option. OpenJDK audio support is still buggy, and if we forgot that gain support issue, Zekr usually crashes when user presses play/pause/stop buttons. Since OpenJDK is not mature enough, specially for Java development, Sun Java is still provided by almost all distributions, so a Linux user should set Zekr to work with Sun Java. Since Sun Java maintains exclusive access to audio device, it may fail if other applications (like a flash loaded in Browser, your music player, or other applications) use audio device, complaining: javax.sound.sampled.LineUnavailableException: Audio Device Unavailable. This can be fixed by wrapping Zekr with padsp, which redirects OSS applications to PulseAudio. A detailed instruction on how to fix Zekr Linux audio problems can be found here.

No comments:

Post a Comment