Play mp3 from the local folder in Unity


(Jerome) #1

I tried to play music from the local folder, but there’s nothing but silence when I run the game. Here’s the code (C#):

using UnityEngine;
using System.Collections;
using FMOD;

public class music: MonoBehaviour {

FMOD.RESULT result;
FMOD.Sound sound1;
FMOD.System system;
FMOD.Channel channel;
FMOD.ChannelGroup channelGroup;

void Start () {
	FMOD.Factory.System_Create (out system);
	result = system.createChannelGroup (null, out channelGroup);
	channel.setChannelGroup (channelGroup);
	result = system.createSound ("C:/song.mp3", FMOD.MODE.DEFAULT, out sound1);
	result = system.playSound (sound1, channelGroup, false, out channel);
	}
}

This script is added as a component to a gameObject on stage.
Thanks in advance.


(Nicholas Wilcox) #2

Add an Update() method to your behaviour and call system.update.