Forum rules - please read before posting.

Playing music that is added during run-time?

Hiya, I'm wondering if it's possible to get AC to play a .wav file that will be added to the game during run time?

To play music right now you have to select a specific file in a directory in the assets folder, but following on from the recording code i was making where players make their own music, it would need to be found at runtime....

Is this possible? 
Thanks :)

Comments

  • Added at runtime as in through a download or an asset bundle?

    It'll take some coding, but should be possible.  Provided you've got a sound added to your assets, and a script reference to it, you can replace a track to the Music Engine with:

    AC.KickStarter.musicStorages[i] = myNewMusicClip;

    musicStorages is a List, so you could alternatively just add the clip to it.  However, I'd recommend you instead create a "dummy" track in your Music Storage Window so that you can still reference it in a Sound: Play music Action.
  • Hey Chris
    Sorry to sound thick but what do you mean by 'script reference to it'? How can you put a script reference on a sound?
    I'm assuming you need it to get this to work
  • I mean you need to have an AudioClip variable named myNewMusicClip that refers to the actual asset.  In your script, place the following above your Start function:

    public AudioClip myNewMusicClip; // The audio clip to insert
    public int i; // The index to replace


    Those will then be exposed as fields you can modify in the Inspector.  But if you're assigning music that gets generated / downloaded at runtime, it's likely you wouldn't be able to supply a track in the Editor.

    As for actually generating / supplying a wav file at runtime, that's not AC-related so you will have to look to e.g. the Unity forums for help on that.
  • Hi Chris,
    No worries about generating the wav file as I've already got that working :)
    Is musicStorages the right line here?
    image
  • Apologies - that should have been:

    AC.KickStarter.settingsManager.musicStorages[i]
  • Hi Chris
    I'm getting an error from the audio clip now haha ;D
    error CS0029: Cannot implicitly convert type `UnityEngine.AudioClip' to `AC.MusicStorage'
  • I'll get there eventually..

    AC.KickStarter.settingsManager.musicStorages[i].audioClip = myNewMusicClip;
  • edited November 2017
    Haha thanks Chris, we're almost there now! :D
    So, no I can't assign it thru editor as wav will be generated at runtime by player

    The filepath is this when saving (saving to the user's computer i assume):
    var filepath = Path.Combine (Application.dataPath, filename);
    filename is customsong.wav btw

    Do I somehow integrate that in the myNewMusicClip?
  • That I'm not sure of - as I said earlier, getting an AudioClip reference at runtime is outside of AC and you'll have to look elsewhere (e.g. Unity's forums) for that.  However, we can help you load it into AC once that part has been solved.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.