How to play a playlist of mp3s randomly?

I have looked through the forums and there were many answers which I tried but I keep getting conversion errors between AudioClip and AudioSource for some reason! I may not be new to programming but I am new to how things are done in Unity and was hoping for some help. Here is all the code I have written, I have even dragged my 3 mp3s into myMusic Array in the inspector but I keep getting Array index is out of range or Object reference not set to an instance of an object. All of my music is located in Assets/Music/ folder.

using UnityEngine;
using System.Collections;

public class Music : MonoBehaviour {

	public AudioSource audio;
	public AudioClip[] myMusic = new AudioClip[3];
	// Use this for initialization
	void Awake () {
		myMusic = Resources.LoadAll("Music",typeof(AudioClip)) as AudioClip[];
		audio.clip = myMusic[0] as AudioClip;
	}
	void Start (){
		
		audio.Play();	
	}
	
	// Update is called once per frame
	void Update () {
		if(!audio.isPlaying)
			playRandomMusic();
	}
	void playRandomMusic()
	{
		audio.clip = myMusic[Random.Range(0,myMusic.Length)] as AudioClip;
		audio.Play();
	}
}

First of all, add an AudioSource component to the object via menu Component/Audio/Audio Source, and delete the AudioSource declaration in your code (audio is a GameObject property). Change also the declaration of myMusic to Object (that’s what LoadAll returns), and don’t initialize it (there’s no need). Finally, remove the type coercion from LoadAll (you can’t coerce type of entire arrays this way). The code would become this:

using UnityEngine;
using System.Collections;
 
public class Music : MonoBehaviour {
 
    Object[] myMusic; // declare this as Object array
	
    void Awake () {
       myMusic = Resources.LoadAll("Music",typeof(AudioClip));
       audio.clip = myMusic[0] as AudioClip;
    }
	
    void Start (){
       audio.Play(); 
    }
 
    // Update is called once per frame
    void Update () {
       if(!audio.isPlaying)
         playRandomMusic();
    }
	
    void playRandomMusic() {
       audio.clip = myMusic[Random.Range(0,myMusic.Length)] as AudioClip;
       audio.Play();
    }
}

NOTE: The audio clips must be inside a folder Resources/Music, or LoadAll won’t find them.

@max_aigneraigner Thanks for the suggestion to reduce issues at build time. What I’m not sure is how you’re loading the audio files to the AudioClip array. I see @aldonaletto solution loads from the resources folder, but you mentioned that’s not efficient? Can you share how you would load the music files into the array?