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 Contributor
Posts: 5
Registered: ‎10-10-2012
My Device: Does it matter
My Carrier: Does it matter
Accepted Solution

Duration of current playing track using mm_renderer

[ Edited ]

Hi there,

 

im writing my own MediaPlayer using Multimedia Renderer Client API. How can I implement getDuration() method(which shall return the duration of the current track in seconds) using this API? Is this even possible? Afaik the default MediaPlayer - bb/multimedia/MediaPlayer wraps the mmr, so there has to be some way of doing this

 

Thanks in advance

Retired
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Duration of current playing track using mm_renderer

Hello iksarp,

 

You can make use of the new event handling mechanism of mm-renderer to achieve this. This is located in the header file: "mm/renderer/events.h". You would will have to wait for the mm-renderer events and look into the dictionary object that it returns, for different events. Specifically, for the "duration" field, it is returned in milliseconds and I am pasting some code snippets below:

 
    // At first, set up everything for the mm-renderer context to run
    // The set up steps should be similar to the existing sample application (https://github.com/blackberry/NDK-Samples/blob/next/VideoPlayback/main.c) but WITHOUT THE BPS EVENT HANDLING for mm-renderer
    // That is, you DO NOT need to do handle BPS event handling if you do the following event handling with "mm/renderer/evenths.h"


    // Now, do the event handling 
    int errorWait;
    const mmr_event_t* event;

    for (;;)  {
    	errorWait = mmr_event_wait( mmr_context );

    	if (errorWait != 0 ) {
    		//TODO: Error handling
    	}
    	// now, get the actual event
    	event = mmr_event_get( mmr_context);


    	switch (event->type) {
    	// TODO: Handle all other switch cases, for the event types
    	case 6:
    		//metadata
    		printf("###### event->type = 6 = MMR_EVENT_METADATA\n");

    		const char *duration = strm_dict_find_value( event->data, "md_title_duration");
    		fprintf(stdout, "duration= %s\n", duration);

    		break;
    	} // switch

    	fflush(stdout);
    } // for

 


Essentially, for every event coming from mm-renderer, a set of attributes are exposed as dictionary items (inside the "data" field), to reflect the current status of the mm-renderer context (for example, playback state, title name, duration, etc).

 

This is new with Beta 3 and the documentation is still not published properly. We apologize for that; I have already raised this issue with the documentation teams and I will try to get them to publish them 


Hope this helps and please let us know if you need anything else.

 

Cheers,

Rashid

New Contributor
Posts: 6
Registered: ‎03-28-2013
My Device: BBZ10
My Carrier: Airtel

Re: Duration of current playing track using mm_renderer

Hi Rashid,

 

I am trying to play 2 audio files continuosly looping without any time delay. I created 2 contexts for that and used the for loop to identify the state and start playing the next context.

It is playing good.

 

But issue arises while stopping the play. I have a button to stop this. But when i press the button am unable to stop the audio play and the app crashes.

 

Please help me out.

 

thanks

Retired
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Duration of current playing track using mm_renderer

Hi luraee,

1) Are you limited to use only the C mm-renderer API? Because you can also just easily create multiple contexts using the Cascades MediaPlayer API (QML/Qt/C++). You can even set the repeat mode for the MediaPlayer object you create and let the API take care of it:

https://developer.blackberry.com/cascades/reference/bb__multimedia__mediaplayer.html#property-repeat...

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

 

2) If you are indeed forced to use the C mm-renderer API, have you looked into the *repeat* parameter for the function *mmr_input_parameters*?

https://developer.blackberry.com/native/reference/bb10/mmrenderer_libref/topic/mmr_api/mmr_input_par...

This should allow you to repeat the playback without having to do it manually like you mentioned here (i.e. waiting for the stopped state; starting playback again)

 

3) The "app crashing" you mentioned below definitely sounds like a bug; either on the platform/OS or on your app. Are you certain the contexts you are dealing with are still present in memory? Please try to reproduce that with a small example/sample app and let us know. Some traces/logs would definitely be helpful. Feel free to create a new item at the Developer Issue Tracker (https://developer.blackberry.com/bdsc/?lang=na&sourceURL=https://www.blackberry.com/jira/secure/Dash... or a separate forum question here accordingly.

 

Hope some of this helps and let us know what you think.

 

Cheers,
Rashid

 

 

 

New Contributor
Posts: 6
Registered: ‎03-28-2013
My Device: BBZ10
My Carrier: Airtel

Re: Duration of current playing track using mm_renderer

Thank you Rashid.

 

I have tried with the media player first.

But i couldnt play a playlist file. Can you give me a sample which will play a playlist file with repeat mode.

 

And also i am not sure of the format of the .m3u file to play. I tried with different formats, but everything failed.

 

thanks,

Retired
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Duration of current playing track using mm_renderer

Hi Luraee,

 

Feel free to open another forum question accordingly with your code (or snippets) on how you actually tried to make the MediaPlayer work with repeat mode work (this thread was for a different question). It should work. If you made your own .m3u file, make sure the file paths are correct and your app has permissions for accessing the *Shared* media directories (for example: "file://accounts/1000/share/.....).


The format of the .m3u file should be this: http://en.wikipedia.org/wiki/M3U#Format

(but you will have to be careful how exactly you are specifying the absolute path).

 

Cheers,

Rashid