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
New Developer
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

MediaPlayer problem in Gold SDK

Hi everybody,

Can you confirm that there are some issues with the MediaPlayer on Gold SDK?

The MediaPlayer works well on qml as an attached object but not in C++

I've tried to implement MediaPlayer like this

 

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

 

The problem is that there was no sound

I also tried to play local file:

 

MediaPlayer mp(this);
mp.setSourceUrl(QUrl("file:///accounts/1000/shared/music/test.mp3"));
mp.play();

Even though 

 

MediaPlayer mp(this);
mp.setSourceUrl("file:///accounts/1000/shared/music/test.mp3");
mp.play();

I've allowed access_shared and there was no sound also!!! :smileysad:

 

So, can you guys got the same problems?

Developer
Posts: 1,652
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: MediaPlayer problem in Gold SDK

works fine for me in OpenDataSpace with sound

.mp3 .ogg .wav .m4a

void OpenDataSpace::invokeBoundMediaPlayer(const QString& uri) {
	qDebug() << "invoke bound mediaplayer" << uri;
	InvokeRequest cardRequest;
	if (uri.startsWith('/')) {
		cardRequest.setUri("file://" + uri);
	} else {
		cardRequest.setUri(uri);
	}
	cardRequest.setTarget("sys.mediaplayer.previewer");
	mInvokeManager->invoke(cardRequest);
}

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
New Developer
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

Re: MediaPlayer problem in Gold SDK

Thanks @ekke, but I dont't want to Invoke any cards, just play the sound in the background :smileysad:

Developer
Posts: 1,652
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: MediaPlayer problem in Gold SDK


longmilk wrote:

Thanks @ekke, but I dont't want to Invoke any cards, just play the sound in the background :smileysad:


aaah - understand. have not done this yet

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Contributor
Posts: 16
Registered: ‎01-04-2013
My Device: BB10 Dev
My Carrier: Rogers Unfortunately

Re: MediaPlayer problem in Gold SDK

I'm encountering the same thing, but only in Release build - I get sound in Debug builds ok.

 

Also, even in debug builds I can't seem to get setSourceUrl to work with a file:// type, and according to docs it's also supposed to work with just "/sounds/test.mp3" and then assume asset:// but it doesn't.

 

Hunting for a solution...

 

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

Re: MediaPlayer problem in Gold SDK

Has anyone managed to solve this yet?
--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Contributor
Posts: 16
Registered: ‎01-04-2013
My Device: BB10 Dev
My Carrier: Rogers Unfortunately

Re: MediaPlayer problem in Gold SDK

I haven't had a chance to go back and test after the last SDK update, I had intended to create a simple repro case for it... but my "solution" to get sound working was to switch my app to use the OpenAL interfaces.  Doesn't play all the same formats, though.

 

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

Re: MediaPlayer problem in Gold SDK

[ Edited ]

This works, ignore the example code:

 

MediaPlayer* mp = new MediaPlayer();
mp->setSourceUrl(QString("file:///accounts/1000/shared/music/2.mp3"));
mp->play();

 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Contributor
Posts: 16
Registered: ‎01-04-2013
My Device: BB10 Dev
My Carrier: Rogers Unfortunately

Re: MediaPlayer problem in Gold SDK

Ah, but that example plays a file that is included in the 'shared' file area.  What if the file is only in the private 'assets' area?

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

Re: MediaPlayer problem in Gold SDK

Use this for any sound that's included in your app:

 

mp->setSourceUrl(QString(QDir::currentPath() +"/app/native/assets/sounds/2.mp3"));

 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone