Quantcast
Channel: naudio Work Item Rss Feed
Viewing all articles
Browse latest Browse all 738

Created Unassigned: Naudio and Unity for looping section [16494]

$
0
0
Hello - I got stuck trying to play a sound from my Unity Assets:


using UnityEngine;
using System.Collections;
using System;
using System.IO;
using NAudio;
using NAudio.Wave;

public class NaudioLooper : MonoBehaviour
{

public AudioClip asWs;

public class StartEndLoopReader{

public TimeSpan _start;
public TimeSpan _end;
public NAudio.Wave.WaveStream _stream;

public StartEndLoopReader(NAudio.Wave.WaveStream stream, TimeSpan start, TimeSpan end)
{
_stream = stream;
_stream.CurrentTime = start;
_start = start;
_end = end;
//return null;
}
}


void Start(){
TimeSpan _startInp =new TimeSpan (0, 0, 2);
TimeSpan _endInp = new TimeSpan (0, 0, 4);
NAudio.Wave.WaveStream _streamInp= new NAudio.Wave.WaveFileReader(@"Asset/Media/Tepotten_coolEditTilret 1w.wav");
NAudio.Wave.WaveOutEvent wo = new NAudio.Wave.WaveOutEvent();
StartEndLoopReader reader = new StartEndLoopReader( _streamInp, _startInp, _endInp);

wo.Init(reader);
wo.Play();
}

public int Read(byte[] array, int offset, int count)
{
Debug.Log(_stream.CurrentTime);
if (_stream.CurrentTime>_end)
{
// back to start to loop
// if you want to stop here, return 0 instead.
_stream.CurrentTime = _start;
}

return _stream.Read(array, offset, count);
}

#region IWaveProvider Members
public WaveFormat WaveFormat
{
get { return _stream.WaveFormat; }
}
#endregion
}


[its based on my workarounds from http://www.ceus-now.com/setting-playback-start-end-points-in-naudio/ ... where I (admit, quite in deperation) tried make StartEndLoopReader a class instead]

For now the "wo.Init(reader);" line causes me the biggest problems.
- what to do?

/best regards

Viewing all articles
Browse latest Browse all 738

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>