Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA
Accepted Solution

MediaPlayer - playing an MP3?

Im using the code from teh following:

 

https://developer.blackberry.com/cascades/reference/bb__multimedia__mediaplayer.html

 

 MediaPlayer mp(this);
	    mp.setSourceUrl(QUrl("/assets/audio/magichour.mp3"));
	    mp.play();

 But the mp3 won't play, any ideas?

 

I've enabled the correct permissions.

 

Cheers

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Retired
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: MediaPlayer - playing an MP3?

Hello Jeff,

 

The MediaPlayer API actually needs the absolute path to do the playback right now (I know, it is a very annoying limitation at the moment; I already this internally and hopefully it will be fixed soon).

If you are packaging the file within the application, you would have to do something like the following:

MediaPlayer mp(this);
mp.setSourceUrl(QDir::currentPath() + "/app/native/assets/sounds/magichour.mp3");
mp.play();

You can also play the media files from the "shared" folders (with the "access_shared" permissions in the bar-descriptor.xml file). In that case, the code could be something like the following:

 

MediaPlayer mp(this);
mp.setSourceUrl("/accounts/1000/shared/music/magichour.mp3");
mp.play();  
Also, note that the simulator has limited support on codecs (only a few audio codecs and no video) for proprietary reasons. Hope that helps and please let us know if you have any further questions. Cheers, Rashid
Retired
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: MediaPlayer - playing an MP3?

Just a quick update on this thread:

In addition to what I mentioned before in the thread already, the following "asset" way of accessing files in the assets folder should also work:

 MediaPlayer mp(this);
	    mp.setSourceUrl(QUrl("asset:///file.mp3"));
	    mp.play();

Note that this solution only went in the most recent public Beta3 OS/SDK (10.0.9.388/10.0.9.386)

New Contributor
Posts: 9
Registered: ‎03-21-2012
My Device: Blackberry Bold - 9700
My Carrier: Airtel

Re: MediaPlayer - playing an MP3?

Can we get duration of track when playing local audio.

I tried mp.duration(). ITs always returning 0.
Is there any otherway to get duration.
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: MediaPlayer - playing an MP3?

You can get the duration of the track's meta data.

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
New Contributor
Posts: 9
Registered: ‎03-21-2012
My Device: Blackberry Bold - 9700
My Carrier: Airtel

Re: MediaPlayer - playing an MP3?

mean

QVariantMap map=mediaPlayer.metaData();
unsigned int duraton =map["duration"];

is it right?