Use timed metadata

You can use TimedMetadata when the current playback time matches the start time.

To use these saved TimedMetadata objects during playback, use the saved ArrayList from Store timed-metadata objects as they are dispatched.

  1. Run a timer and repeatedly query the current playback time.

  2. Find all of the TimedMetadata objects with start times that match the current playback time.

    You can use these objects to complete various actions.


    When checking whether the current playback time matches any TimedMetadata objects, include shouldTriggerSubscribedTagEvent as a condition.

    The timeline might change as the result of various ad behaviors. For example, one or more ad breaks might be moved from their original positions on the timeline, but shouldTriggerSubscribedTagEvent ensures that the TimeMetadata object’s start time matches the current playback time.

    For example:

     _playbackClockEventListener = new Clock.ClockEventListener() {
        public void onTick(String name) {
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    /* handle timedmetadata object list  */
                    if (_mediaPlayer != null && _timedMetadataList != null && _timedMetadataList.size() > 0) {
                        if (_lastKnownStatus == MediaPlayer.PlayerState.PLAYING) {
                            long localTime = _mediaPlayer.getLocalTime();
                            Iterator<TimedMetadata> iterator = _timedMetadataList.iterator();
                            while (iterator.hasNext()) {
                                TimedMetadata timedMetadata =;
                                long diff = localTime - timedMetadata.getTime();
                                if (diff >= 0 &&
                                    diff <= PLAYBACK_CLOCK_INTERVAL &&
                                    _mediaPlayer.shouldTriggerSubscribedTagEvent()) {
                                    // use timed metadata object
  3. Periodically flush stale TimedMetadata instances from the list to prevent memory from continuously growing.

On this page