music loops specific time of the song

hello, is the pimera time I write and I’m using unity some time ago. good to the point. You can make a loop with a song ogg vorbis from a specific time? not repeat the whole song?. I ask this because in a program called RPG Maker can do, if within the song is called LoopStart and LOOPLENGTH information indicating from where do the loop. there will be some script to do this?

In the newest rpg maker mv they released their core source. Here’s the code in javascript that they use to get the metadata info from an ogg file. This is in javascript, and won’t work in Unity, but you’ll get the basic idea. You’re going to have to loop through the metadata and find where an entry says “LOOPSTART” or “LOOPLENGTH” or even “LOOPEND” or whatever you’ like. You might have to use an external dll to read the file.

WebAudio.prototype._readOgg = function(array) {
    var index = 0;
    while (index < array.length) {
        if (this._readFourCharacters(array, index) === 'OggS') {
            index += 26;
            var vorbisHeaderFound = false;
            var numSegments = array[index++];
            var segments = [];
            for (var i = 0; i < numSegments; i++) {
                segments.push(array[index++]);
            }
            for (i = 0; i < numSegments; i++) {
                if (this._readFourCharacters(array, index + 1) === 'vorb') {
                    var headerType = array[index];
                    if (headerType === 1) {
                        this._sampleRate = this._readLittleEndian(array, index + 12);
                    } else if (headerType === 3) {
                        this._readMetaData(array, index, segments*);*

}
vorbisHeaderFound = true;
}
index += segments*;*
}
if (!vorbisHeaderFound) {
break;
}
} else {
break;
}
}
};
WebAudio.prototype._readMetaData = function(array, index, size) {
for (var i = index; i < index + size - 10; i++) {
if (this._readFourCharacters(array, i) === ‘LOOP’) {
var text = ‘’;
while (array > 0) {
text += String.fromCharCode(array[i++]);
}
if (text.match(/LOOPSTART=([0-9]+)/)) {
this._loopStart = parseInt(RegExp.$1);
}
if (text.match(/LOOPLENGTH=([0-9]+)/)) {
this._loopLength = parseInt(RegExp.$1);
}
if (text == ‘LOOPSTART’ || text == ‘LOOPLENGTH’) {
var text2 = ‘’;
i += 16;
while (array > 0) {
text2 += String.fromCharCode(array[i++]);
}
if (text == ‘LOOPSTART’) {
this._loopStart = parseInt(text2);
} else {
this._loopLength = parseInt(text2);
}
}
}
}
};
You can implement this yourself in Unity. I’m planning to myself so when I do I’ll send you back the source.

The simplest solution? Look on the asset store and use any of the top audio tools on there.

What you could do though, is cut up the loop files, then instead of using Audio.Play, use Audio.PlayDelayed, and just loop it.

You can also set the loop start, and loop end points, then just stop, and then play at the new start again… However this might cause hiccups in the sound quality.