Exemple #1
0
    IEnumerator Start()
    {
#if UNITY_EDITOR
        var reqest = UnityWebRequest.Get("file://" + Application.dataPath + "/music.mp3");
        Debug.Log("Directory is : " + "file://" + Application.dataPath + "/music.mp3");
#else
        var reqest = UnityWebRequest.Get("file://" + Application.dataPath + "/../music.mp3");
        Debug.Log("Directory is : " + "file://" + Application.dataPath + "/../music.mp3");
#endif

        yield return(reqest.SendWebRequest());

        while (reqest.downloadProgress < 1.0)
        {
            yield return(null);
        }


        if (reqest.isNetworkError)
        {
            Debug.Log(reqest.error);
        }
        else
        {
            GetComponent <AudioSource>().clip = NAudioPlayer.FromMp3Data(reqest.downloadHandler.data);
        }
        GetComponent <AudioSource>().Play();
    }
    private void DirSearch(string sDir)
    {
        DebugLog("Reading Directory: {0}", sDir);
        try
        {
            foreach (var d in Directory.GetDirectories(sDir))
            {
                DirSearch(d);
            }

            foreach (var f in Directory.GetFiles(sDir))
            {
                if (IgnoredTracks.Contains(f) || AudioFiles.Contains(f) || !NAudioPlayer.IsSupportedFileType(f))
                {
                    continue;
                }

                DebugLog("Found File: {0}", Path.GetFileName(f));
                AudioFiles.Add(f);
            }
        }
        catch (System.Exception ex)
        {
            DebugLog("Failed to find files due to Exception: {0}", ex.Message);
        }
    }
Exemple #3
0
        public MainWindowVm()
        {
            Logger.Info("Initializing MainWindow View Model");
            TagEditorVm      = new TagEditorVm();
            BpmCalc          = new BpmTapper();
            CurrentSongIndex = 0;
            MainPlayer       = new NAudioPlayer(App.Configuration.MainPlayerDeviceNum, true);
            PreviewPlayer    = new NAudioPlayer(App.Configuration.SecondaryPlayerDeviceNum,
                                                App.Configuration.UpdatePlaycountOnPreview);
            MainPlayer.Volume    = App.Configuration.MainPlayerVolume;
            PreviewPlayer.Volume = App.Configuration.SecondaryPlayerVolume;

            MainPlayer.SongCompletedEvent += (sender, args) =>
            {
                Logger.Info("Song completed; playing next song");
                NextCmd.Execute(null);
            };

            MainPlayer.PropertyChanged    += MainPlayerPropertyChanged;
            PreviewPlayer.PropertyChanged += PreviewPlayerPropertyChanged;

            _columnManager = new ColumnManager();

            BindingOperations.EnableCollectionSynchronization(
                App.SongDb.Songs,
                (App.SongDb.Songs as ICollection).SyncRoot);
            BindingOperations.EnableCollectionSynchronization(
                App.SongDb.GroupCategories,
                (App.SongDb.GroupCategories as ICollection).SyncRoot);

            lock ((App.SongDb.Songs as ICollection).SyncRoot)
            {
                DisplayedSongs = new ListCollectionView(App.SongDb.Songs);
            }

            lock ((App.SongDb.GroupCategories as ICollection).SyncRoot)
            {
                AddGroupDescriptions(0, App.SongDb.GroupCategories);
                App.SongDb.GroupCategories.CollectionChanged +=
                    GroupCategoriesCollectionChanged;
                lock (_displayedSongs)
                {
                    DisplayedSongs.Filter = SongFilter;
                    DisplayedSongs.Refresh();
                }
            }

            lock ((App.SongDb.Columns as ICollection).SyncRoot)
            {
                ((App.SongDb.Columns) as INotifyCollectionChanged).CollectionChanged
                    += OnColumnsChange;
                foreach (var col in App.SongDb.Columns)
                {
                    AddColumn(col);
                }
            }

            SongQueue = new ObservableCollection <Song>();
            Logger.Info("Done initializing MainWindow view model");
        }
        /// <summary>
        /// Plays the song or sound located at the path's location.
        /// </summary>
        /// <param name="path">The full path of the file to play.</param>
        public void PlayFile(string path)
        {
            bool    isMusic = Path.GetExtension(path) != ".wav";
            IPlayer music;

            try
            {
                try { music = new IrrPlayer(path, isMusic); }
                catch (Exception) { music = new NAudioPlayer(path, isMusic); }
            }
            catch (Exception)
            {
                MessageBox.Show("Audio Player was unable to play the track you selected. The format may not be supported on your system.",
                                "Audio Playback Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            music.Play();
            if (isMusic)
            {
                StopMusic();
                _musicName           = Path.GetFileNameWithoutExtension(path);
                _music               = music;
                trackNameLabel.Text  = @"Now Playing: " + _musicName;
                playTool.Text        = @"Playing";
                playTool.Image       = _playIcons.Images["play"];
                pauseTool.Enabled    = true;
                pauseTool.CheckState = CheckState.Unchecked;
                stopTool.Enabled     = true;
            }
        }
Exemple #5
0
    IEnumerator LoadMP3File(string path)
    {
        WWW www = new WWW("file://" + path);

        //Debug.Log ("loading " + path);
        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        AudioClip clip = NAudioPlayer.FromMp3Data(www.bytes);

        clip.LoadAudioData();

        if (clip.loadState == AudioDataLoadState.Failed)
        {
            Debug.LogError("Unable to load file: " + path);
        }
        else
        {
            //Debug.Log ("done loading " + path);
            clip.name = Path.GetFileName(path);

            loadedMusics.Add(clip);

            MasterAudio.AddSongToPlaylist("Loaded Musics", clip);
        }

        loadingMusicsList.Remove(path);
    }
Exemple #6
0
    // a method to play a preview of the currently hovered-over track
    private IEnumerator PreviewTrack(string musicPath)
    {
        Debug.Log("Starting preview for " + musicPath);
        string _url = string.Format("file://{0}", musicPath);
        //UnityWebRequest _unityWebRequest = new UnityWebRequest(_url);

        //while (!_unityWebRequest.isDone)
        //{
        //    yield return null;
        //}

        //_unityWebRequest = UnityWebRequestMultimedia.GetAudioClip(_url, AudioType.MPEG);
        //audioSource.clip = DownloadHandlerAudioClip.GetContent(_unityWebRequest);

        WWW _www = new WWW(_url);

        while (!_www.isDone)
        {
            yield return(null);
        }

        AudioClip _clip = NAudioPlayer.FromMp3Data(_www.bytes);

        audioSource.clip = _clip;

        Debug.Log("Loaded.");

        audioSource.Play();
        audioSource.time = audioStartTime;

        currentSongPath = musicPath;

        // audioSource.volume = 0;
    }
Exemple #7
0
    private IEnumerator ImportAudio()
    {
        //path = EditorUtility.OpenFilePanel("Select song", "", "mp3");
        paths = StandaloneFileBrowser.OpenFilePanel("Select Song", "", "mp3", false);
        try
        {
            path = paths[0];
        }
        catch (Exception ex)
        {
            // If no file was selected stop the application
            Quit();
        }
        string url   = "file:///" + path;
        WWW    audio = new WWW(url);



        while (!audio.isDone)
        {
            yield return(0);
        }


        testAudio   = NAudioPlayer.FromMp3Data(audio.bytes);
        source.clip = testAudio;
        source.Play();
        sampleRate = AudioSettings.outputSampleRate;

        audioReady = true;
    }
Exemple #8
0
    private static void LoadAudio_Tool(object obj)
    {
        string path = obj as string;

        AudioClip clip;

        //FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
        //fileStream.Seek(0, SeekOrigin.Begin);
        //创建文件长度缓冲区
        //byte[] bytes = new byte[fileStream.Length];
        byte[] bytes = File.ReadAllBytes(path);
        //读取文件
        //fileStream.Read(bytes, 0, (int)fileStream.Length);
        //释放文件读取流
        //fileStream.Close();
        //fileStream.Dispose();
        //fileStream = null;
        if (bytes.Length != 0)
        {
            //WWW www = new WWW(musicfilepath);
            clip = NAudioPlayer.FromMp3Data(bytes);
        }
        else
        {
            clip = null;
        }
    }
Exemple #9
0
    // loads and plays song
    private IEnumerator LoadTrack(string path, SongParser.Metadata _metadata)
    {
        Debug.Log(path);
        string _url = string.Format("file://{0}", path);
        //UnityWebRequest _unityWebRequest = new UnityWebRequest(_url);

        //while (!_unityWebRequest.isDone)
        //{
        //    yield return null;
        //}

        //_unityWebRequest = UnityWebRequestMultimedia.GetAudioClip(_url, AudioType.MPEG);
        //audioSource.clip = DownloadHandlerAudioClip.GetContent(_unityWebRequest);

        WWW _www = new WWW(_url);

        while (!_www.isDone)
        {
            yield return(null);
        }

        AudioClip _clip = NAudioPlayer.FromMp3Data(_www.bytes);

        audioSource.clip = _clip;

        Debug.Log("Loaded.");

        songLoaded = true;

        audioSource.Play();

        GameObject _controller = GameObject.FindGameObjectWithTag("GameController");

        _controller.GetComponent <NoteGenerator>().InitNotes(_metadata);
    }
Exemple #10
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var videoProvider   = new OcvVideoProvider(new ObservableTimer(this.timer));
            var videoRecorder   = new VideoRecorder();
            var audioRecorder   = new NAudioRecorder();
            var audioPlayer     = new NAudioPlayer();
            var audioRepository = new NAudioRepository();
            var brain           = new OcvBrain();

            controller = new Controller();

            videoProvider.Init();
            videoRecorder.Init(videoProvider);
            audioRecorder.Init();
            brain.Init();
            controller.Init(brain, videoProvider, videoRecorder, audioRecorder, audioPlayer, audioRepository);

            lifetimeSubscriptions = new CompositeDisposable()
            {
                brain.FrameRecognized.ObserveOn(this).Subscribe(OnFrameRecognized),
                videoProvider.FrameAvailable.ObserveOn(this).Subscribe(OnFrameAvailable),
            };

            videoProvider.StartStreaming();
        }
Exemple #11
0
 private void SetupSession()
 {
     player = new NAudioPlayer(session);
     session.PrefferedBitrate = BitRate.Bitrate320k;
     player.Init();
     noPlayingLabel.DataContext = player;
 }        
Exemple #12
0
    private IEnumerator LoadAsset(FileInfo playerFile, Action <AudioClip> callback)
    {
        string    uri     = "file://" + playerFile.FullName.ToString();
        AudioType type    = playerFile.Extension == ".mp3" ? AudioType.MPEG : AudioType.WAV;
        var       request = UnityWebRequestMultimedia.GetAudioClip(uri, type);

        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log(request.error);
        }
        else
        {
            AudioClip clip;
            if (type == AudioType.MPEG)
            {
                clip = NAudioPlayer.FromMp3Data(request.downloadHandler.data);
            }
            else
            {
                clip = DownloadHandlerAudioClip.GetContent(request);
            }
            clip.name = Path.GetFileNameWithoutExtension(playerFile.FullName);
            callback(clip);
        }
    }
Exemple #13
0
    AudioClip MakeAudioClip(string path)
    {
        string ext = Path.GetExtension(path);

        if (audioExtensions.Contains(ext))
        {
            try
            {
                if (ext == ".mp3")
                {
                    return(NAudioPlayer.FromMp3Data(new WWW("file:///" + path).bytes));
                }
                else
                {
                    AudioClip clip = new WWW("file:///" + path).GetAudioClip();
                    while (clip.loadState != AudioDataLoadState.Loaded)
                    {
                    }
                    return(clip);
                }
            }
            catch (Exception ex)
            {
                Log("Failed to load sound sound file {0} due to Exception: {1}\nStack Trace {2}", path, ex.Source, ex.StackTrace);
            }
        }
        return(null);
    }
Exemple #14
0
    // Asks the user for an mp3 (wav will also work but isn't shown), NAudio.dll turns it into a wav, and holds it for the visualizer.
    IEnumerator Start()
    {
        DontDestroyOnLoad(this.gameObject);

        string path = EditorUtility.OpenFilePanel("Music File To Open", "", "mp3");
        string url  = "file:///" + path;

        using (WWW www = new WWW(url)){
            if (path.Length != 0 && path != null)
            {
                yield return(www);

                music = NAudioPlayer.FromMp3Data(www.bytes);
                if (music.length != 0 || music != null)
                {
                    SceneManager.LoadScene("OptionsScene");
                }
                else
                {
                    EditorUtility.DisplayDialog("Error! File failed to load.", "Please select a valid mp3 file.", "Whoops!");
                    SceneManager.LoadScene("StartScene");
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Error! File failed to load.", "Please select a valid mp3 file.", "Whoops!");
                SceneManager.LoadScene("StartScene");
            }
        }
    }
    IEnumerator ReadClip(string path)
    {
        DestroyImmediate(audioSource.clip);
        WWW www = new WWW("file://" + path);

        int startNameIndex = path.LastIndexOf("\\") + 1;
        int endNameIndex   = path.LastIndexOf(".");

        audioName.text = path.Substring(startNameIndex, endNameIndex - startNameIndex);
        string fileDir = path.Substring(0, startNameIndex);

        while (!www.isDone)
        {
            yield return(null);
        }

        if (path.Contains(".mp3"))
        {
            audioSource.clip = NAudioPlayer.FromMp3Data(www.bytes);
        }
        else
        {
            audioSource.clip = www.GetAudioClip(false);
        }

        onAudioChange.Invoke(audioSource.clip.length);
        onAudioLoaded.Invoke(audioName.text, fileDir);
        openExplorerButton.interactable = true;
    }
Exemple #16
0
    IEnumerator LoadFileByNAudio(string filePath, NAudioPlayer.SupportFormatType type)
    {
        if (type != NAudioPlayer.SupportFormatType.NULL)
        {
            WWW www = new WWW("file://" + filePath);
            yield return(www);

            if (null != www && null != www.bytes && www.bytes.Length > 0)
            {
                AudioClip clip = NAudioPlayer.GetClipByType(www.bytes, type);
                if (null != clip)
                {
                    while (clip.loadState == AudioDataLoadState.Loading)
                    {
                        yield return(null);
                    }
                    if (clip.loadState == AudioDataLoadState.Loaded)
                    {
                        clip.name = Path.GetFileNameWithoutExtension(filePath);
                    }
                }
                if (!PlaySounds(clip))
                {
                    MarkPlayErrorItem(filePath);
                }
            }
        }
    }
Exemple #17
0
        static async Task <int> _RunAsync(Options options)
        {
            // https://github.com/naudio/NAudio/blob/master/Docs/OutputDeviceTypes.md
            Device device = _GetDevice(options);

            if (options.ListDevices)
            {
                string[] deviceList = device.List().ToArray();
                foreach (string d in deviceList)
                {
                    Console.WriteLine(d);
                }

                return(0);
            }

            HelloMessage helloMessage = new HelloMessage(_GetMacAddress(), _GetOS(), options.Instance);

            helloMessage.Version = string.Join(".", s_Version.Major, s_Version.Minor, s_Version.Build);
            Player     player     = new NAudioPlayer(options.DacLatency, options.BufferDurationMs, options.OffsetToleranceMs, device.DeviceFactory);
            Controller controller = new Controller(player, helloMessage);

            await controller.StartAsync(options.HostName, options.Port);

            return(0);
        }
Exemple #18
0
    IEnumerator LoadAudioFromAsset(FileInfo playerFile)
    {
        if (playerFile.Name.Contains("meta"))
        {
            yield return("");
        }
        else
        {
            print(playerFile.FullName.ToString());
            string wwwPlayerFilePath = "file://" + playerFile.FullName.ToString();
            WWW    www = new WWW(wwwPlayerFilePath);
            yield return(www);

            if (playerFile.Name.Contains(".wav"))
            {
                _DestiantionAudio.clip = www.GetAudioClip(true, true);
            }
            if (playerFile.Name.Contains(".mp3"))
            {
                _DestiantionAudio.clip = NAudioPlayer.FromMp3Data(www.bytes); //www.GetAudioClip();
            }
            _DestiantionAudio.clip.name = playerFile.Name;
            _DestiantionAudio.Play();
        }
    }
Exemple #19
0
    static AudioClip LoadBGM(string path)
    {
        string type = Path.GetExtension(path).Replace(".", "");

        Debug.Log("[Audio] path=" + path + " | type=" + type);
        AudioClip       myClip = null;
        UnityWebRequest www    = null;

        byte[] byteArray;
        try
        {
            switch (type.ToLower())
            {
            case "ogg":
                    #if UNITY_STANDALONE || UNITY_EDITOR
                www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.OGGVORBIS);
                www.SendWebRequest();
                while (!www.isDone)
                {
                }
                myClip = DownloadHandlerAudioClip.GetContent(www);
                    #else
                byteArray = File.ReadAllBytes(path);
                myClip    = WAV.FromOggData(byteArray);
                    #endif
                break;

            case "mp3":
                    #if UNITY_STANDALONE || UNITY_EDITOR
                byteArray = File.ReadAllBytes(path);
                myClip    = NAudioPlayer.FromMp3Data(byteArray);
                    #else
                www = UnityWebRequestMultimedia.GetAudioClip("file://" + path, AudioType.MPEG);
                www.SendWebRequest();
                while (!www.isDone)
                {
                }
                myClip = DownloadHandlerAudioClip.GetContent(www);
                    #endif
                break;

            case "wav":
                byteArray = File.ReadAllBytes(path);
                myClip    = WAV.FromWavData(byteArray);
                break;

            default:
                Debug.LogError("Unexpected audio type");
                return(null);
            }
            Debug.Log("[Audio] Audio Length: " + myClip.length);
            return(myClip);
        }
        catch (System.Exception e)
        {
            Debug.LogError("[Audio]錯誤!" + e);
            return(null);
        }
    }
Exemple #20
0
        public void DeInitPlugin()
        {
            try
            {
                // 置き換えたTTSメソッドを元に戻す
                if (this.originalTTSDelegate != null)
                {
                    ActGlobals.oFormActMain.PlayTtsMethod = this.originalTTSDelegate;
                }

                // FF14監視スレッドを開放する
                FF14Watcher.Deinitialize();

                // 漢字変換オブジェクトを開放する
                KanjiTranslator.Default.Dispose();

                // 設定を保存する
                TTSYukkuriConfig.Default.Save();

                // TTSサーバを終了する
                TTSServerController.End();

                // プレイヤを開放する
                NAudioPlayer.DisposePlayers();

                // TTS用waveファイルを削除する?
                if (TTSYukkuriConfig.Default.WaveCacheClearEnable)
                {
                    var appdir = Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                        @"anoyetta\ACT");

                    if (Directory.Exists(appdir))
                    {
                        foreach (var file in Directory.GetFiles(appdir, "*.wav"))
                        {
                            try
                            {
                                File.Delete(file);
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                lblStatus.Text = "Plugin Exited";
            }
            catch (Exception ex)
            {
                ActGlobals.oFormActMain.WriteExceptionLog(
                    ex,
                    "TTSゆっくりプラグインの終了時に例外が発生しました。");
            }
        }
        /// <summary>
        /// 再生デバイスを列挙する
        /// </summary>
        private void EnumrateDevices()
        {
            try
            {
                this.PlayerComboBox.Enabled     = false;
                this.mainDeviceComboBox.Enabled = false;
                this.subDeviceComboBox.Enabled  = false;

                var devices = NAudioPlayer.EnumlateDevices();

                // 再生デバイスコンボボックスを設定する
                this.mainDeviceComboBox.DisplayMember = "Name";
                this.mainDeviceComboBox.ValueMember   = "ID";
                this.mainDeviceComboBox.DataSource    = devices.ToArray();

                this.subDeviceComboBox.DisplayMember = "Name";
                this.subDeviceComboBox.ValueMember   = "ID";
                this.subDeviceComboBox.DataSource    = devices.ToArray();

                var defaultDeviceID = devices
                                      .Select(x => x.ID)
                                      .FirstOrDefault() ?? string.Empty;

                if (string.IsNullOrWhiteSpace(TTSYukkuriConfig.Default.MainDeviceID))
                {
                    TTSYukkuriConfig.Default.MainDeviceID = defaultDeviceID;
                }

                if (string.IsNullOrWhiteSpace(TTSYukkuriConfig.Default.SubDeviceID))
                {
                    TTSYukkuriConfig.Default.SubDeviceID = defaultDeviceID;
                }

                if (devices.Count > 0)
                {
                    this.mainDeviceComboBox.SelectedValue = TTSYukkuriConfig.Default.MainDeviceID;
                    this.subDeviceComboBox.SelectedValue  = TTSYukkuriConfig.Default.SubDeviceID;

                    if (string.IsNullOrWhiteSpace(this.mainDeviceComboBox.Text))
                    {
                        this.mainDeviceComboBox.SelectedIndex = 0;
                    }

                    if (string.IsNullOrWhiteSpace(this.subDeviceComboBox.Text))
                    {
                        this.subDeviceComboBox.SelectedIndex = 0;
                    }
                }
            }
            finally
            {
                this.PlayerComboBox.Enabled     = true;
                this.mainDeviceComboBox.Enabled = true;
                this.subDeviceComboBox.Enabled  = this.enabledSubDeviceCheckBox.Checked;
            }
        }
Exemple #22
0
        public override SampleFormat SetHeader(byte[] buffer)
        {
            m_FlacHeader = buffer;
            MemoryStream stream = new MemoryStream(buffer);

            using (FlacReader reader = new FlacReader(stream))
            {
                return(NAudioPlayer.WaveFormatToSampleFormat(reader.WaveFormat));
            }
        }
Exemple #23
0
 public Form1()
 {
     InitializeComponent();
     CheckForIllegalCrossThreadCalls = false;
     player         = new NAudioPlayer();
     player.OnPeak += Player_OnPeak;
     FormClosing   += (obj, args) => {
         player?.Dispose();
     };
 }
Exemple #24
0
 public IEnumerator testThing(WWW testWWW)
 {
     this.gameObject.AddComponent <AudioSource>();
     while (!testWWW.isDone)
     {
         yield return(0);
     }
     this.gameObject.GetComponent <AudioSource>().clip = NAudioPlayer.FromMp3Data(testWWW.bytes);
     Debug.Log("done");
 }
    /// <summary>
    /// Loads and converts music file to the proper format.
    /// </summary>
    /// <param name="path">Path to the music file.</param>
    /// <returns>Converted music file.</returns>
    private AudioClip LoadMusic(string path)
    {
        string _url = string.Format("file://{0}", path);

        WWW _www = new WWW(_url);

        AudioClip _musicClip = NAudioPlayer.FromMp3Data(_www.bytes);

        _musicClip.name = Path.GetFileName(path);
        return(_musicClip);
    }
Exemple #26
0
    private void AsyncLoadAudio(string path)
    {
        byte[]    bytes     = File.ReadAllBytes(path);
        AudioClip monoaudio = NAudioPlayer.FromMp3Data(bytes);


        LoadAudio(monoaudio);


        Reset();
    }
    public static IEnumerator DesignateMusicFolder(Action onConvertClip)
    {
        string path = EditorUtility.OpenFolderPanel("Designate music folder", "", "");

        string[] files = Directory.GetFiles(path);

        DirectoryInfo dirInfo = new DirectoryInfo(path);

        FileInfo[] fileInfos = dirInfo.GetFiles();

        foreach (string fileName in files)
        {
            if (fileName.EndsWith(".mp3") || fileName.EndsWith(".wav"))
            {
                Debug.Log("Path string is : " + fileName);
                AudioClip convertedClip = null;


                // If the file is an mp3, we first convert it to a wav.
                if (fileName.EndsWith(".mp3"))
                {
                    WWW www = new WWW(fileName);
                    while (!www.isDone)
                    {
                        yield return(0);
                    }

                    convertedClip = NAudioPlayer.FromMp3Data(fileName);
                }

                if (fileName.EndsWith(".wav"))
                {
                    WAV wav = new WAV(fileName);

                    convertedClip = AudioClip.Create("testSound", wav.SampleCount, 1, wav.Frequency, false);
                    convertedClip.SetData(wav.LeftChannel, 0);
                }

                if (convertedClip != null && !SongManager.instance.HasSong(convertedClip))
                {
                    AddSongToGlobalManager(convertedClip);
                }
            }
        }

        if (onConvertClip != null)
        {
            onConvertClip();
        }

        yield return(null);

        //SongChoiceMenu.instance.SpawnCassettesFromSongs();
    }
    //From https://gamedev.stackexchange.com/questions/112699/play-soundcloud-in-unity-3d
    /// <summary>
    /// Experimental soundcloud playback, currently waiting for api access
    /// </summary>
    /// <returns></returns>
    IEnumerator playSoundcloud()
    {
        WWW www = new WWW(soundcloudLink);

        while (!www.isDone)
        {
            yield return(0);
        }
        audioSource.clip = NAudioPlayer.FromMp3Data(www.bytes);
        //audioSource.clip = www.GetAudioClip(false, true);
    }
    IEnumerator LoadSongCoroutine(string path)
    {
        string url = string.Format("file://{0}", path);
        WWW    www = new WWW(url);

        while (!www.isDone)
        {
            yield return(null);
        }

        Music.clip = NAudioPlayer.FromMp3Data(www.bytes);
    }
Exemple #30
0
    public IEnumerator PlayMP3(string path)
    {
        /* Play *.mp3 audio files */
        path = "file://" + path;
        WWW www = new WWW(path);

        yield return(www);

        clip     = NAudioPlayer.FromMp3Data(www.bytes);
        src.clip = clip;
        src.Play();
    }
Exemple #31
0
    private IEnumerator _RequestAudioByWebRequestInPC(string path)
    {
        using (var audio_clip_request = UnityWebRequest.Get(path)) {
            yield return(audio_clip_request.SendWebRequest());

            if (audio_clip_request.isNetworkError || audio_clip_request.isHttpError)
            {
                Debug.LogError(audio_clip_request.error);
                yield break;
            }

            _audioSource.clip = NAudioPlayer.FromMp3Data(audio_clip_request.downloadHandler.data);
        }
    }
Exemple #32
0
 /// <summary>
 /// Plays the song or sound located at the path's location.
 /// </summary>
 /// <param name="path">The full path of the file to play.</param>
 public void PlayFile(string path)
 {
     bool isMusic = Path.GetExtension(path) != ".wav";
     IPlayer music;
     try
     {
         try { music = new IrrPlayer(path, isMusic); }
         catch (Exception) { music = new NAudioPlayer(path, isMusic); }
     }
     catch (Exception)
     {
         MessageBox.Show("Sound Test was unable to play the track you selected. The format may not be supported on your system.",
             "Audio Playback Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     music.Play();
     if (isMusic)
     {
         StopMusic();
         _musicName = Path.GetFileNameWithoutExtension(path);
         _music = music;
         trackNameLabel.Text = @"Now Playing: " + _musicName;
         playTool.Text = @"Playing";
         playTool.Image = _playIcons.Images["play"];
         pauseTool.Enabled = true;
         pauseTool.CheckState = CheckState.Unchecked;
         stopTool.Enabled = true;
     }
 }