Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

I don't think my .ogg file is importing correctly into StreamingAssets

Discussion in 'Editor & General Support' started by CumbrianCyclist, Nov 10, 2019.

  1. CumbrianCyclist

    CumbrianCyclist

    Joined:
    Jul 3, 2018
    Posts:
    6
    Hello.

    I'm making a game and this is like a level editor that I'm doing at the moment.

    The player selects a song title and a song artist. The player then chooses a .ogg file from their HDD.
    The .ogg file gets stored as "StreamingAssets/tempSong/songArtist/songTitle/song.ogg"

    Next the player plays the song. I have this code

    using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("File://" + Application.streamingAssetsPath + "/tempSong/" + songInfo.songArtist + "/" + songInfo.songTitle + "/song.ogg", AudioType.OGGVORBIS))
    {
    yield return www.SendWebRequest();

    song = DownloadHandlerAudioClip.GetContent(www);


    Now all of this seems to work except the song loading as an audioclip. The script loads a file, but it's blank. Next to "Song: " it's just the icon of an audioclip and a blank name.

    Now after struggling with this for a few days I noticed that dragging an .ogg file into the StreamingAssets folder doesn't really seem to import anything. It's just blank on the inspector. If I drag it into any other folder I get the sound wave, the import options, etc. Is this the problem?

    The reason I'm using StreamingAssets is because I want the player to be able to take the files out of the folder when they're done and drag it into the actual games folder. Perhaps this isn't the best way to go about users adding content?

    Sorry if it's confusing. I've been struggling with this for the last few days and my brain is mushed.

    Thanks!
     
  2. CumbrianCyclist

    CumbrianCyclist

    Joined:
    Jul 3, 2018
    Posts:
    6
    Aha! This code works! But it says its obsolete...


    IEnumerator GetAudioClip()
    {
    var path = "File://" + Application.streamingAssetsPath + "/tempSong/" + songInfo.songArtist + "/" + songInfo.songTitle + "/song.ogg";
    // Start downloading
    using (var download = new WWW(path))
    {
    // Wait for download to finish
    yield return download;
    // Create ogg vorbis file
    var clip = download.GetAudioClip();
    // Play it
    if (clip != null)
    {
    source.clip = clip;
    source.Play();
    }
    else // Handle error
    {
    Debug.Log("Ogg vorbis download failed. (Incorrect link?)");
    }
    }
    }