Search Unity

Getting audio clip data from currently playing track

Discussion in 'Timeline' started by themeshpotato, Apr 8, 2019.

  1. themeshpotato

    themeshpotato

    Joined:
    Apr 11, 2018
    Posts:
    55
    Is there an easy way to get the currently playing audio clip from a timeline audio track?
    I can't seem to find anything that would let me do this in the API, but I might have overlooked something.

    If I set the audio source of the track to a specific one the clip is not set on that audio source either so it seems everything is happening behind the scenes.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Simple answer - no. The clip doesn't get 'set' anywhere that is easily accessible, like the AudioSource.

    The only solution I can think of is to search the timeline for audio clips that overlap at the current time.
     
  3. themeshpotato

    themeshpotato

    Joined:
    Apr 11, 2018
    Posts:
    55
    Okay, thanks @seant_unity for the quick reply!|
    Is there an easy way to create custom AudioPlayableAssets?
    For example when I want to create a clip that links audio with subtitles, but still plays on an audio track?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    You can subclass AudioPlayableAsset, but the UI wasn't really designed with that in mind, so a few workarounds may be required to get it to work in Editor.

    For example, to add clips of the new type, you may need to drag and drop the script file.
     
  5. themeshpotato

    themeshpotato

    Joined:
    Apr 11, 2018
    Posts:
    55
    @seant_unity Hmm okay, if I subclass AudioPlayableAsset I can no longer preview the audio.
    Did I forget to override a specific method or does the preview not work for subclasses?
    Because audio visualization works on the clip.
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    I would have expected that to work. Are you overriding CreatePlayable by chance?
     
  7. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Anyone know if there's a better way of doing this yet? Or maybe something coming in Unity 2020? I have the exact same problem with subtitling.