- Home /
Question by
AlienBoyGames · Nov 27, 2019 at 02:50 PM ·
audioaudioclipcustom editorcustomaudioplay
Play audio in editor with a start time.
Hello I am trying to play audio in a custom editor and set the start sample time.
public static void PlayClip(AudioClip clip, int startSample = 0, bool loop = false)
{
System.Reflection.Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
System.Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
System.Reflection.MethodInfo method = audioUtilClass.GetMethod(
"PlayClip",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public,
null,
new System.Type[] { typeof(AudioClip), typeof(int), typeof(bool) },
null
);
method.Invoke(
null,
new object[] { clip, startSample, loop }
);
}
If anyone knows how to do it please help me :)
Comment
Your answer
Follow this Question
Related Questions
How to make audio not playing repeatedly? 1 Answer
How do I play audio source on Maximize on Play / Audio Source wont play on Maximize 0 Answers
Stop audio from looping and play at lower volume 1 Answer
How to Switch The Audio Clip using button 0 Answers
How can I play audio clips depending on the players movement 0 Answers