Search Unity

Audio 2018.3 Cannot set the time samples for the partially downloaded audio clip

Discussion in 'Audio & Video' started by WereVarg, Jan 5, 2019.

  1. WereVarg

    WereVarg

    Joined:
    Apr 9, 2012
    Posts:
    20
    Before the 2018.3 released we lived happily with the following code:

    Code (CSharp):
    1. public IEnumerator Stream(string soundId)
    2.     {
    3.         ..
    4.         var www = new WWW(path);
    5.    
    6.         float downloadLimit = 0.05f;  
    7.         while (www.progress < downloadLimit)
    8.         {
    9.             ...
    10.             yield return new WaitForSeconds(0.1f);
    11.         }    
    12.         AudioClip myAudioClip = www.GetAudioClip(false, true, AudioType.MPEG);
    13.         DownloadContainer.audioClip = myAudioClip;  //setting audioclip and we can start Play or Rewind using clip.timeSamples
    14.         DownloadContainer.isDone = true;
    15.         yield return null;
    16.         while (www.progress < 1)
    17.         {
    18.             DownloadContainer.progress = www.progress;
    19.             yield return null;
    20.         }
    21.     }
    now we get the error if we try to change clip.timeSamples before the track is downloaded


    C:\buildslave\unity\build\Modules/Audio/Public/sound/SoundChannel.cpp(356) : Error executing result (Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format. )
    UnityEngine.AudioSource.Play()


    and now we have to block the Rewind possibility and get the AudioClip again after the download complete


    myAudioClip = www.GetAudioClip(false, true, AudioType.MPEG);
    DownloadTrackContainer.Result = myAudioClip;


    and now we are able to scroll through it.

    Any ideas?
     
    Last edited: Jan 11, 2019
  2. janusl

    janusl

    Unity Technologies

    Joined:
    Aug 8, 2018
    Posts:
    24
    Hi WereVarg,

    Just to understand your use case perfectly: Before 2018.3 you wanted to & were able to:
    1. download a clip partially
    2. seek the clip (.timeSamples)
    3. play it
    Without issues? Or do you just use seeking to rewind to the start?

    Regards, Janus
     
  3. WereVarg

    WereVarg

    Joined:
    Apr 9, 2012
    Posts:
    20
    Yes, exactly, we used seeking in both directions. Now we aren't able to set audioClip.timeSamples while it is marked as streamed: using true inside
    AudioClip myAudioClip = www.GetAudioClip(false, true, AudioType.MPEG);

    or setting DownloadHandlerAudioClip.stream = true; using WebRequest
     
  4. janusl

    janusl

    Unity Technologies

    Joined:
    Aug 8, 2018
    Posts:
    24
    Alright, can I get you to submit a bug report?
     
    aliakseipashkel and WereVarg like this.
  5. IndieGamesStudio

    IndieGamesStudio

    Joined:
    Sep 4, 2015
    Posts:
    2
    the same here it could be unity bug
     
  6. aliaksei_kalosha

    aliaksei_kalosha

    Joined:
    Jul 20, 2014
    Posts:
    5
    aliakseipashkel, janusl and WereVarg like this.
  7. MMOERPG

    MMOERPG

    Joined:
    Mar 21, 2014
    Posts:
    50
    Is this fixed? I believe I am experiencing the same issue.

    Even after the audio file .mp3 has finished downloading, I cannot seek through the track and get this error message:
    "Error executing result (Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format. )"

    To seek I am using AudioSource.time = float

    Using Unity 2019.3.0f3 Personal <DX11>

    Am I not using it properly?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class audio : MonoBehaviour
    7. {
    8.     private AudioSource audioSource;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         audioSource = gameObject.GetComponent<AudioSource>();
    13.         StartCoroutine(StreamAudio());
    14.     }
    15.  
    16.     public IEnumerator StreamAudio() {
    17.         using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://www.4sync.com/web/directDownload/V-6bvf3y/lLTlC1js.9a0fcc060df0faa4206af8af3501eaae", AudioType.MPEG)) {
    18.             ((DownloadHandlerAudioClip)www.downloadHandler).streamAudio = true;
    19.             www.SendWebRequest();
    20.             while (www.downloadProgress < 0.01) {
    21.                 Debug.Log(www.downloadProgress);
    22.                 yield return new WaitForSeconds(.1f);
    23.             }
    24.             if (www.isNetworkError) {
    25.                 Debug.Log(www.error);
    26.             }else {
    27.                 AudioClip audioClip = ((DownloadHandlerAudioClip)www.downloadHandler).audioClip;
    28.                 audioSource.clip = audioClip;
    29.                 audioSource.Play();
    30.             }
    31.             while (www.downloadProgress < 1) {
    32.                 audioSource.clip = ((DownloadHandlerAudioClip)www.downloadHandler).audioClip;
    33.                 yield return new WaitForSeconds(0.1f);
    34.             }
    35.             audioSource.clip = ((DownloadHandlerAudioClip)www.downloadHandler).audioClip;
    36.         }
    37.     }
    38.     public void SeekAudio() {
    39.         audioSource.time = audioSource.time + 15;
    40.     }
    41. }
     
    Last edited: Jan 5, 2020
  8. janusl

    janusl

    Unity Technologies

    Joined:
    Aug 8, 2018
    Posts:
    24
    Seeking and streaming never really was possible, except for a brief window in our lineage under very specific circumstances and only using certain codecs. See the bug report for more info.

    It is obviously a very usable feature, and we are looking at how we can properly implement it.
     
    MMOERPG likes this.
  9. MMOERPG

    MMOERPG

    Joined:
    Mar 21, 2014
    Posts:
    50
    Thank you for the post!
    I'm confused. This whole post is about seeking a streamed audio clip using UnityWebRequest. You told WereVarg to submit a bug report because this was not working.
    The bug report at https://issuetracker.unity3d.com/is...e-partially-downloaded-audio-clip-doesnt-work states that the bug has been fixed as of Unity 2019.3

    But you're saying that seeking a audio clip that has been streamed is not a feature that Unity supports?

    Is there more to the bug report than the page that the link above takes me to?
     
  10. WereVarg

    WereVarg

    Joined:
    Apr 9, 2012
    Posts:
    20
    After the track was downloaded we kinda recreated audioclip again to make it work. Am not sure right now what we did but try to get it with the stream set to false after the download is done. https://docs.unity3d.com/ScriptReference/WWW.GetAudioClip.html using this or setting downloadHandler.streamAudio to false.
     
  11. WereVarg

    WereVarg

    Joined:
    Apr 9, 2012
    Posts:
    20
    They've resolved it as "by design", we used some backdoor accidentally left open ).
     
  12. MMOERPG

    MMOERPG

    Joined:
    Mar 21, 2014
    Posts:
    50
    @WereVarg
    Thanks for the reply!
    I appreciate the clarification.
    Ill try your suggestions.