- Home /
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?
How about you just stop playing the music and start it again at the repeat point. Just look at the Documentation
Answer by astracat111 · Oct 24, 2016 at 05:23 AM
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[i]);
}
vorbisHeaderFound = true;
}
index += segments[i];
}
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[i] > 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[i] > 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.
Answer by Cynikal · Oct 24, 2016 at 04:06 AM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115208im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnAudioRead Buffer Changing Sizes? 1 Answer
Is there a way to create a random Audiosource loop? 2 Answers
Gun Audio reverbs off of Terrian- sounds horrible- What can I do? 0 Answers
Play sound on animation event? 3 Answers
How do I stream audio from disk? 0 Answers