Multimedia on BlackBerry 7 was based on the multimedia JSR (135). There were a lot of limitations regarding supported formats, how many sounds could be played at the same time, and even what worked on which device.

In BlackBerry 10, there are a wide range of supported codecs, containers, and protocols.

For video, we recommend an MP4 containing H.264 video at 720p and AAC audio. For audio, it depends a lot on your use case. In addition to mainstays such as MP3 and AAC, we support things like FLAC and Ogg Vorbis.

To actually play your multimedia, you should be looking at the MediaPlayer class. That will handle audio or video. You can also easily play the built in system sounds with the SystemSound class.

Recording audio is through the AudioRecorder class. You can record a few different formats, including AAC (.mp4) and PCM (.wav).

This is all pretty straightforward and should be pretty easy to adjust to if you are used to the Java way of doing things. There are a few key differences that you might not be expecting though.

The first is the NowPlayingConnection. If you are building any sort of media player type application: use it. What it does is let the user control the volume and playback of your app from in another app, using the volume keys on the side. You can also provide a bit of data like a thumbnail image and the current song playing. No user is going to want to have to go back into your application just to change the volume, and it’s really easy to implement.

Secondly, unlike in BlackBerry 7, in BlackBerry 10 you can enable echo cancellation in order to do VoIP. There is no convenient Qt API to do this, but you can use QSA and open a connection to the “voice” PCM audio interface.

The other big difference is that you can’t just feed bytes directly into the media player. You need to have an actual file to play, or be using one the streaming protocols supported. Of course, there is nothing stopping you from dropping down to OpenAL/ALUT and doing whatever you need if that’s your style. You also have QSA available as mentioned before, as well as mm-renderer (which is what MediaPlayer is using), but that is all beyond the scope of this article.


Originally posted here:

BlackBerry Java to BlackBerry 10 Cascades Porting Series – Part 4: Multimedia