FileDocCategorySizeDatePackage
MediaSyncEvent.javaAPI DocAndroid 5.1 API4546Thu Mar 12 22:22:30 GMT 2015android.media

MediaSyncEvent

public class MediaSyncEvent extends Object
The MediaSyncEvent class defines events that can be used to synchronize playback or capture actions between different players and recorders.

For instance, {@link AudioRecord#startRecording(MediaSyncEvent)} is used to start capture only when the playback on a particular audio session is complete. The audio session ID is retrieved from a player (e.g {@link MediaPlayer}, {@link AudioTrack} or {@link ToneGenerator}) by use of the getAudioSessionId() method.

Fields Summary
public static final int
SYNC_EVENT_NONE
No sync event specified. When used with a synchronized playback or capture method, the behavior is equivalent to calling the corresponding non synchronized method.
public static final int
SYNC_EVENT_PRESENTATION_COMPLETE
The corresponding action is triggered only when the presentation is completed (meaning the media has been presented to the user) on the specified session. A synchronization of this type requires a source audio session ID to be set via {@link #setAudioSessionId(int) method.
private final int
mType
private int
mAudioSession
Constructors Summary
private MediaSyncEvent(int eventType)


       
        mType = eventType;
    
Methods Summary
public static android.media.MediaSyncEventcreateEvent(int eventType)
Creates a synchronization event of the sepcified type.

The type specifies which kind of event is monitored. For instance, event {@link #SYNC_EVENT_PRESENTATION_COMPLETE} corresponds to the audio being presented to the user on a particular audio session.

param
eventType the synchronization event type.
return
the MediaSyncEvent created.
throws
java.lang.IllegalArgumentException



                                                         
        
                              
        if (!isValidType(eventType)) {
            throw (new IllegalArgumentException(eventType
                    + "is not a valid MediaSyncEvent type."));
        } else {
            return new MediaSyncEvent(eventType);
        }
    
public intgetAudioSessionId()
Gets the synchronization event audio session ID.

return
the synchronization audio session ID. The returned audio session ID is 0 if it has not been set.

        return mAudioSession;
    
public intgetType()
Gets the synchronization event type.

return
the synchronization event type.

        return mType;
    
private static booleanisValidType(int type)

        switch (type) {
        case SYNC_EVENT_NONE:
        case SYNC_EVENT_PRESENTATION_COMPLETE:
            return true;
        default:
            return false;
        }
    
public android.media.MediaSyncEventsetAudioSessionId(int audioSessionId)
Sets the event source audio session ID.

The audio session ID specifies on which audio session the synchronization event should be monitored. It is mandatory for certain event types (e.g. {@link #SYNC_EVENT_PRESENTATION_COMPLETE}). For instance, the audio session ID can be retrieved via {@link MediaPlayer#getAudioSessionId()} when monitoring an event on a particular MediaPlayer.

param
audioSessionId the audio session ID of the event source being monitored.
return
the MediaSyncEvent the method is called on.
throws
java.lang.IllegalArgumentException

        if (audioSessionId > 0) {
            mAudioSession = audioSessionId;
        } else {
            throw (new IllegalArgumentException(audioSessionId + " is not a valid session ID."));
        }
        return this;