public void ReadPage() { string word = wordsOnPage[wordIndex++]; string url = string.Format (baseUrl, word); WWW www = new WWW(url); source = this.GetComponentInParent<AudioSource> (); source.clip = www.audioClip; status = SoundStatus.PlayingPage; }
public void SayWord(GameObject button) { Text text = button.GetComponentInChildren<Text>(); string word = text.text; string url = string.Format (baseUrl, word); WWW www = new WWW(url); source = this.GetComponentInParent<AudioSource> (); source.clip = www.audioClip; status = SoundStatus.PlayingSingle; wordsOnPage.Add (word); page.AddWord (word); }
/// <summary> /// 临时更改音量(用于淡入淡出) /// </summary> /// <param name="time">变动时间</param> /// <param name="change">相对变化百分比(0,1)</param> public void ChangeVolume(float time, float change) { //0+1 恢复至user deltaTime = time; if (change < 0) { finalVolume = userVolume * (1 + change); } else { finalVolume = userVolume * change; } deltaVolume = Mathf.Abs(currentSource.volume - finalVolume); status = SoundStatus.VolumeChange; }
/// <summary> /// Start or resume playing current <see cref="SoundStream"/> object. /// </summary> protected override void Play() { // Check if the sound parameters have been set if (_format == 0) { throw new InvalidOperationException( "Audio parameters must be initialized before played."); } bool isStreaming = false; SoundStatus state = SoundStatus.Stopped; lock (_mutex) { isStreaming = _isStreaming; state = _state; } if (isStreaming && (state == SoundStatus.Paused)) { // If the sound is paused, resume it lock (_mutex) { _state = SoundStatus.Playing; ALChecker.Check(() => AL.SourcePlay(Handle)); } return; } else if (isStreaming && (state == SoundStatus.Playing)) { // If the sound is playing, stop it and continue as if it was stopped Stop(); } // Move to the beginning OnSeek(TimeSpan.Zero); // Start updating the stream in a separate thread to avoid blocking the application _processed = 0; _isStreaming = true; _state = SoundStatus.Playing; _thread.Start(); }
/// <summary> /// Start or resume playing of the <see cref="SoundStream"/>. /// </summary> /// <inheritdoc/> protected internal override void Play() { if (format == 0) { throw new Exception("Failed to play audio stream:\nSound parameters have not been initialized"); } bool streaming = false; var state = SoundStatus.Stopped; lock (mutex) { streaming = this.streaming; state = this.state; } // Check whether the stream is active if (streaming) { // If the sound is paused, resume it if (state == SoundStatus.Paused) { lock (mutex) { this.state = SoundStatus.Playing; } ALChecker.Check(() => AL.SourcePlay(Handle)); return; } else if (state == SoundStatus.Playing) { Stop(); } } // Set playing status this.state = SoundStatus.Playing; this.streaming = true; // Start streaming the audio sample task = Task.Run(() => StreamDataAsync()); }
private bool nowChannel; // 現在のチャンネルがどちらかの判断用trueがChannelBase void Start() { //まずは子オブジェクト(このスクリプトがついたオブジェクト)についたオーディオソースを取得 audioSource = GetComponent <AudioSource>(); //"SoundMaster_Obj"オブジェクトからSoundMasterを取得 soundmaster = GameObject.Find("SoundMaster_Obj").GetComponent <SoundMaster>(); soundStatus = GameObject.Find("SoundStatus_Obj").GetComponent <SoundStatus>(); // 最初にどこのデータを参照するか名前で指定→名前から配列番号を取得(名前間違えると悲惨なので注意) child_number = soundStatus.namenumber.IndexOf(Sound_Name); //AudioCilpを親から取得 child_audioclip = soundmaster.list_size[child_number].audioclip; //AudioSource内に上記オーディオクリップを格納 audioSource.clip = child_audioclip; //spatialBlend(2Dか3Dかの割合、ブレンド率。)→変化するようにする //audioSource.spatialBlend = 0;//0→2D 1→3D //下記関数等で使用している FirstBase(soundmaster.list_size[child_number].ChannelBase, soundmaster.list_size[child_number].ObjectBase); //rolloffMode → これでmaxDistanceに影響するモードを変更する。モードはLogarithmic、Linear、Customの3種類。 // (Customはスクリプトからいじれないらしいので、影響があるのはLogarithmic、Linearの2種類)デフォルトはLogarithmicモードになっている。 // また、Unity上の該当プルダウンメニューを操作すると、maxDistanceの値に変化はなかったので、最初からモードを選択した状態でいじるのが前提になると思う //モードの変更は下記のようなスクリプトとなる audioSource.rolloffMode = AudioRolloffMode.Logarithmic; //デフォルト通りの形なので今のところ実質意味はない //maxDistance→Logarithmicモードでは音が減衰を停止する距離(減衰の停止がどういう意味かは不明(volumeが0になるという意味なのかただ単に止まるだけなのか)) // Linearモードでは音が完全に聞こえなくなる距離 audioSource.maxDistance = 500; //(Logarithmicモード)デフォルト通りの形なので今のところ実質意味はない //minDistance→この値の外側に行くと減衰が開始される audioSource.minDistance = 1; //デフォルト通りの形なので今のところ実質意味はない }
void Play() { currentSource.volume = userVolume; currentSource.Play(); status = SoundStatus.Play; }
public void Stop() { status = SoundStatus.Stopped; }
void UpdatePlaySingle() { if (!playingSingle) { if (!source.isPlaying && source.clip.isReadyToPlay) { source.Play (); playingSingle = true; } } else { playingSingle = false; status = SoundStatus.Stopped; } }
void UpdatePlayPage() { if (!playingPage) { if (!source.isPlaying && source.clip.isReadyToPlay) { source.Play (); playingPage = true; } } else { if (!source.isPlaying) { if (wordIndex < wordsOnPage.Count) { playingPage = false; ReadPage(); } else { status = SoundStatus.Stopped; playingPage = false; wordIndex = 0; } } } }
private static extern int GetStatusNative(int handle, out SoundStatus status);
private AudioClip child_audioclip; //引っ張ってくるclipを格納する用 private void Start() { //"SoundManager"オブジェクトからSoundMasterを取得 soundmaster = GameObject.Find("SoundMaster_Obj").GetComponent <SoundMaster>(); soundStatus = GameObject.Find("SoundStatus_Obj").GetComponent <SoundStatus>(); }
/// <summary> /// Pause the current <see cref="SoundStream"/> object. /// </summary> protected override void Pause() { lock (_mutex) { if (!_isStreaming) return; _state = SoundStatus.Paused; } ALChecker.Check(() => AL.SourcePause(Handle)); }