void SongEnd()
        {
            try
            {
                endSongTime = CurrentTime;
                if (readFullyStream != null)
                {
                    readFullyStream.Close();
                }

                myAudioSource.Stop();
                _uAudio.Stop();

                myAudioSource.clip = null;
                //    myAudioSource.time = 0;
                updateTime    = false;
                _loadedTarget = false;
                State         = uAudio_backend.PlayBackState.Stopped;
                try
                {
                    if (sendPlaybackState != null)
                    {
                        sendPlaybackState(uAudio_backend.PlayBackState.Stopped);
                    }
                }
                catch
                {
                    UnityEngine.Debug.LogWarning("sendPlaybackState #897j8h2432a1q");
                }
            }
            catch
            {
                throw new Exception("Song end #7cgf87dcf7sd8csd");
            }
        }
Exemple #2
0
 public void send_data(uAudio_backend.PlayBackState songState)
 {
     // connect here to get when the song is changes state
     //songState == uAudio_backend.PlayBackState.Playing
     //songState == uAudio_backend.PlayBackState.Stopped
     //songState == uAudio_backend.PlayBackState.Paused
     // UnityEngine.Debug.LogWarning("sendPlaybackState: " + v.ToString() + "---- 7ts87dt");
 }
Exemple #3
0
 void OnPlayBackState(uAudio_backend.PlayBackState valIN)
 {
     //if (!readyNextSong)
     {
         if (valIN == uAudio_backend.PlayBackState.Stopped)
         {
             if (my_uAudioPlayer_UI.my_uAudioPlayer.TotalTime == my_uAudioPlayer_UI.my_uAudioPlayer.CurrentTime)
             {
                 //readyNextSong = true;
                 //     MoveNextSong();
                 //g5eh565h56
                 //readyNextSong = false;
                 StartCoroutine(runNextSong());
                 //     MoveNextSong();
             }
         }
     }
 }
 public void Pause()
 {
     if (State == uAudio_backend.PlayBackState.Playing)
     {
         myAudioSource.Pause();
         State = uAudio_backend.PlayBackState.Paused;
         try
         {
             if (sendPlaybackState != null)
             {
                 sendPlaybackState(uAudio_backend.PlayBackState.Paused);
             }
         }
         catch
         {
             UnityEngine.Debug.LogWarning("sendPlaybackState #whrth546h56h56");
         }
     }
     else
     {
         if (State == uAudio_backend.PlayBackState.Paused)
         {
             myAudioSource.UnPause();
             State = uAudio_backend.PlayBackState.Playing; try
             {
                 if (sendPlaybackState != null)
                 {
                     sendPlaybackState(uAudio_backend.PlayBackState.Playing);
                 }
             }
             catch
             {
                 UnityEngine.Debug.LogWarning("sendPlaybackState #56y53y5tge56");
             }
         }
     }
 }
Exemple #5
0
 public void Play(uAudio_backend.PlayBackState v)
 {
     UnityEngine.Debug.LogWarning("sendPlaybackState: " + v.ToString() + "---- 7ts87dt");
 }
        public void Play(TimeSpan?startOff = null)
        {
#if uAudio_debug
            UnityEngine.Debug.LogWarning("&c&");
#endif
            if (State != uAudio_backend.PlayBackState.Playing)
            {
#if uAudio_debug
                UnityEngine.Debug.LogWarning("&d&");
#endif
                if (State == uAudio_backend.PlayBackState.Paused)
                {
                    Pause();
                }
                else
                {
                    State = uAudio_backend.PlayBackState.Playing;

                    try
                    {
                        //LoadFile(targetFile);
#if uAudio_debug
                        UnityEngine.Debug.LogWarning("B");
#endif
                        SongDone          = false;
                        flare_SongEnd     = false;
                        UAudio.targetFile = targetFile;

                        if (myAudioSource.clip == null)
                        {
#if uAudio_debug
                            UnityEngine.Debug.LogWarning("%B1%");
#endif
                            if (UAudio.LoadMainOutputStream())
                            {
#if uAudio_debug
                                UnityEngine.Debug.LogWarning("%B2%");
#endif

#if !UNITY_STANDALONE_WIN && blank
                                //WWW w = new WWW(targetFile);

                                //int song_sampleSize;
                                //SongReadLoop = new AudioClip.PCMReaderCallback(Song_Stream_Loop);
#if uAudio_debug
                                UnityEngine.Debug.LogWarning("%B4%");
#endif
                                //song_sampleSize = (int)UAudio.uwa.audioPlayback.TotalSamples;
#if uAudio_debug
                                UnityEngine.Debug.LogWarning("%B5%");
#endif
                                if (!targetFile.StartsWith("file://"))
                                {
                                    targetFile = "file://" + targetFile;
                                }

                                var www = new UnityEngine.WWW(targetFile);

                                UnityEngine.AudioClip myAudioClip = www.GetAudioClip(true, false, UnityEngine.AudioType.MPEG);                                // UnityEngine.AudioType.MPEG);

                                //  yield return www;
                                // Next line hangs
                                var clip = myAudioClip;
                                int i    = 100;

                                // todo : check this -=---> clip.loadState != UnityEngine.AudioDataLoadState.Loaded
#if !UNITY_2_6 && !UNITY_2_6_1 && !UNITY_3_0 && !UNITY_3_0_0 && !UNITY_3_1 && !UNITY_3_2 && !UNITY_3_3 && !UNITY_3_4 && !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 && !UNITY_4_6 && !UNITY_4_7
                                while (clip.loadState != UnityEngine.AudioDataLoadState.Loaded && i > 0)
#endif
                                {
                                    i--;
                                    System.Threading.Thread.Sleep(10);
                                }
                                myAudioSource.clip = clip;
#else
#if !UNITY_STANDALONE_WIN && !UNITY_EDITOR
                                if (!targetFile.StartsWith("file://"))
                                {
                                    targetFile = "file://" + targetFile;
                                }
#endif


                                long song_sampleSize;
#if uAudio_debug
                                UnityEngine.Debug.LogWarning("%B3%");
#endif
                                AudioClip.PCMReaderCallback SongReadLoop;
                                SongReadLoop = new AudioClip.PCMReaderCallback(Song_Stream_Loop);

                                System.IO.Stream s = System.IO.File.OpenRead(targetFile);

                                if (readFullyStream != null)
                                {
                                    readFullyStream.Dispose();
                                }

                                readFullyStream = new uAudioDemo.Mp3StreamingDemo.ReadFullyStream(s);
                                readFullyStream.stream_CanSeek = true;

                                byte[]          buff = new byte[1024];
                                NLayer.MpegFile c    = new NLayer.MpegFile(readFullyStream, true);
                                //playbackDevice = m;

                                if (startOff == TimeSpan.Zero)
                                {
                                    c.ReadSamples(buff, 0, buff.Length);
                                }

                                playbackDevice = c;
                                //   UAudio.TotalTime
                                //     song_sampleSize = playbackDevice.Length;// * playbackDevice.SampleRate;
                                song_sampleSize = UAudio.SongLength;
                                // hack
                                // song_sampleSize = int.MaxValue;// need to better alocate this

                                int setSongSize;
                                if (song_sampleSize > int.MaxValue)
                                {
                                    UnityEngine.Debug.LogWarning("uAudioPlayer - Song size over size on int #4sgh54h45h45");
                                    setSongSize = int.MaxValue;
                                }
                                else
                                {
                                    setSongSize = (int)song_sampleSize;
                                }

                                myAudioSource.clip =
                                    UnityEngine.AudioClip.Create("uAudio_song", setSongSize,
                                                                 c.WaveFormat.Channels,
                                                                 c.WaveFormat.SampleRate,
                                                                 true, SongReadLoop);

                                if (!startOff.HasValue)
                                {
                                    CurrentTime = TimeSpan.Zero;
                                }
                                else
                                {
                                    CurrentTime = startOff.Value;
                                }
#endif


                                try
                                {
                                    if (sendPlaybackState != null)
                                    {
                                        sendPlaybackState(uAudio_backend.PlayBackState.Playing);
                                    }
                                }
                                catch
                                {
                                    UnityEngine.Debug.LogWarning("theAudioStream_sendStartLoopPump #32fw46hw465h45h");
                                }
#if uAudio_debug
                                UnityEngine.Debug.LogWarning("%B6%");
#endif
                            }
                            else
                            {
                                myAudioSource.clip = null;
                            }
                        }
                        else
                        {
#if uAudio_debug
                            UnityEngine.Debug.LogWarning("%B!%");
#endif
                        }

                        if (myAudioSource.clip != null)
                        {
#if uAudio_debug
                            UnityEngine.Debug.LogWarning("%B7%");
#endif
                            if (!myAudioSource.isPlaying)
                            {
                                myAudioSource.Play();
                            }

#if uAudio_debug
                            UnityEngine.Debug.LogWarning("%B8%");
#endif
                            updateTime = true;
                        }
                        else
                        {
                            State = uAudio_backend.PlayBackState.Stopped;
                        }
                    }
                    catch (System.Exception ex)
                    {
#if uAudio_debug
                        UnityEngine.Debug.LogWarning("%B9%" + System.Environment.NewLine + ex.Message);
#endif
                        State = uAudio_backend.PlayBackState.Stopped;
                        UnityEngine.Debug.LogWarning("uAudioPlayer - Play #j356j536j356j56j");
                        UnityEngine.Debug.LogWarning(ex);
                    }
                }
            }
        }