Detect Audio Track Has Finished Playing

by BlackBerry Development Advisor on ‎11-21-2011 03:05 PM (3,250 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 );
        }
      }
    }
  }