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 Knowledge Base

Detect Audio Track Has Finished Playing

by Administrator on ‎11-21-2011 03:05 PM - edited on ‎11-21-2011 03:05 PM by BlackBerry Development Advisor (Retired) (3,017 Views)

You are able to detect when an audio track that was launched using mmr_play() has finished playing.  At the end of the media the state changes to MMR_STOPPED.  Stopping at the end of media can be distinguished from stopping due to an error or from a forced stop by an mmr_stop() call by checking the error info.  If the stop was caused by the end of media, there will be error info but the error code will be zero (MMR_ERROR_NONE).

 

mmrenderer_state_t st = mmrenderer_event_get_state(ev);
  if ( st != oldstate ) {  // Could also be a speed change without a state change
    if ( st == MMR_STOPPED) {
      const mmr_error_info_t *ei  = mmrenderer_event_get_error( ev );
      if ( ei == NULL ) {
        report( "stopped by calling mmr_stop()" );
      } else {
        const char *pos = mmrenderer_event_get_error_position( ev );
        if ( ei->error_code == MMR_ERROR_NONE ) {
          report( "finished playing at %s", pos );
        } else {
          report( "stopped by error #%d at %s", ei->error_code, pos );
        }
      }
    }
  }

 

Contributors