Пример #1
0
 private void Play()
 {
     if (FilePath == null)
     {
         return;
     }
     if (FilePath != null)
     {
         _audioPlayback?.Play();
         _trackBarTimer.Start();
     }
 }
        public void PlaySelectedAudioFile()
        {
            //Play selected audio file

            //if(AudioControl != null)
            //{
            //    AudioControl.PlayAudio();
            //}

            //Trying new method

            audioPlayback.Play();
        }
        public bool Play()
        {
            if (!audioPlayback.IsInitialized)
            {
                return(false);
            }
            if (audioPlayback.IsPlaying)
            {
                return(false);
            }
            // Already at end of timeline?
            if (sequencer.CursorPosition >= sequencer.TimelineLength)
            {
                return(false);
            }

            audioPlayback.Seek(sequencer.CursorPosition - MusicTimeOffset);
            audioPlayback.Play();
            cursorUpdateTimer.Start();
            Notify(nameof(IsPlaying));
            return(true);
        }
Пример #4
0
        public void MoverBase(Movement movement)
        {
            if (encendido == false)
            {
                return;
            }
            if (Main.Instancia.PracticaIniciada == false)
            {
                return;
            }
            Vector3 posC1 = new Vector3(cuchillaPos1);
            Vector3 posC2 = new Vector3(cuchillaPos2);

            Vector3 posTorno = new Vector3(baseTornoPos);

            switch (movement)
            {
            case Movement.Backward:
                posC1.Z    += speed;
                posC2.Z    += speed;
                posTorno.Z += speed;
                break;

            case Movement.Forward:
                posC1.Z    -= speed;
                posC2.Z    -= speed;
                posTorno.Z -= speed;
                break;

            case Movement.Left:
                posC1.X    -= speed;
                posC2.X    -= speed;
                posTorno.X -= speed;
                break;

            case Movement.Right:
                posC1.X    += speed;
                posC2.X    += speed;
                posTorno.X += speed;
                break;
            }
            if (Main.Instancia.Escena.Pieza.ChequearCollision(posC1) ||
                Main.Instancia.Escena.Pieza.ChequearCollision(posC2))
            {
                speed = Main.Instancia.Escena.Pieza.Material.Resistencia / 350;
                AudioPlayback.Play("rebajado.mp3");
                Vector3 v = new Vector3(cuchillaPos1);
                v.Scale(scale);
                Main.Instancia.Escena.AddGenerator(new ChispaGenerator(v));
            }
            else
            {
                counterSpeed++;
                if (counterSpeed == 22)
                {
                    counterSpeed = 0;
                    speed        = speedBase;
                }

                //if (movement == Movement.Left || movement == Movement.Right)
                //{
                //    Controladora.Instancia.CleanGenerator();
                //}
            }
            if (movement == Movement.Left || movement == Movement.Right)
            {
                Main.Instancia.Escena.ClearGenerator();
            }
            if (movement == Movement.Backward)
            {
                Main.Instancia.Escena.CleanGenerator();
                AudioPlayback.StopSound("rebajado.mp3");
            }

            if (posTorno.Z < 2.37f && posTorno.Z > 0.06f && // aki se dan los topes
                (movement == Movement.Forward || movement == Movement.Backward))
            {
                baseTornoPos.Z = posTorno.Z;
                cuchillaPos1.Z = posC1.Z;
                cuchillaPos2.Z = posC2.Z;
            }
            if (posTorno.X > -5.84 && posTorno.X < 3.25f &&
                (movement == Movement.Left || movement == Movement.Right))
            {
                baseTornoPos.X = posTorno.X;
                cuchillaPos1.X = posC1.X;
                cuchillaPos2.X = posC2.X;
            }


            if (posC1.Y < 0.1f)// para que no parta la pieza
            {
                return;
            }

            Main.Instancia.Escena.Pieza.RebajarPieza(cuchillaPos1);
            Main.Instancia.Escena.Pieza.RebajarPieza(cuchillaPos2);
        }
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                Title      = _title;
                NeteaseUrl = "http://music.163.com/#/my/m/music/playlist?id=6435531";
                SongCollection.Add(new Song()
                {
                    Title   = new Title("Clover Heart's"),
                    Artists = new Artists(new string[] { "榊原ゆい", "榊原ゆい" }),
                    Album   = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"),
                });
                SongCollection.Add(new Song()
                {
                    Title   = new Title("Clover Heart's"),
                    Artists = new Artists(new string[] { "榊原ゆい" }),
                    Album   = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"),
                });
                SongCollection.Add(new Song()
                {
                    Title   = new Title("Clover Heart's"),
                    Artists = new Artists(new string[] { "榊原ゆい" }),
                    Album   = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"),
                });
                SelectedSong = SongCollection.First();
            }
            else
            {
                // Code runs "for real"
                Title                      = _title;
                NeteaseUrl                 = "http://music.163.com/playlist?id=6435531";
                Progress                   = 0;
                audioPlayback              = new AudioPlayback();
                audioPlayback.Volume       = Volume;
                audioPlayback.EndCallback += (handle, channel, data, user) =>
                {
                    int index = -1;
                    if ((index = SongCollection.IndexOf(CurrentPlaySong)) != -1)
                    {
                        ListenCommand.Execute(SongCollection.ElementAt((index + 1) % SongCollection.Count));
                    }
                    else
                    {
                        audioPlayback.Stop();
                        NowPlaying = "";
                        CurrentPlaySong.PlayProgress = 0;
                        CurrentPlaySong.PlayStatus   = PlayStatus.Play;
                        timer.Enabled = false;
                        timer.Stop();
                    }
                };

                timer.Tick += (sender, args) =>
                {
                    Title = string.Format("{0}/{1} - {2}", audioPlayback.CurrentLength, audioPlayback.TotalLength, _title);
                    RaisePropertyChanged("Title");
                    CurrentPlaySong.PlayProgress = audioPlayback.Progress;
                };

                GetSongsCommand = new RelayCommand(async() =>
                {
                    if (string.IsNullOrWhiteSpace(NeteaseUrl))
                    {
                        return;
                    }
                    var id      = "";
                    var urlType = "";
                    var reg     = new Regex(@".*/(.*?)\?id=(\d*)").Match(NeteaseUrl);
                    if (reg.Success)
                    {
                        urlType = reg.Groups[1].Value;
                        id      = reg.Groups[2].Value;
                        SongCollection.Clear();
                        switch (urlType)
                        {
                        case "album":
                            foreach (var song in await NeteaseUtil.GetSongsFromAlbum(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;

                        case "artist":
                            foreach (var song in await NeteaseUtil.GetSongsFromArtist(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;

                        case "playlist":
                            foreach (var song in await NeteaseUtil.GetSongsFromPlaylist(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;

                        case "song":
                            foreach (var song in await NeteaseUtil.GetSongDetail(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;
                        }
                    }
                    else
                    {
                        SongCollection.Clear();
                        foreach (var song in await NeteaseUtil.SearchSongs(NeteaseUrl))
                        {
                            SongCollection.Add(song);
                            RaisePropertyChanged("TotalCount");
                        }
                    }
                });

                PlaylistDownloadCommand = new RelayCommand <Song>((song) =>
                {
                    SelectedSong = song;
                    if (string.IsNullOrWhiteSpace(SongTrackUrl))
                    {
                        return;
                    }
                    var downloader = new DownloadUtils();
                    downloader.DownloadProgressChanged += (sender, args) =>
                    {
                        song.DownProgress   = args.ProgressPercentage;
                        BytesReceived       = args.BytesReceived.ToString();
                        TotalBytesToReceive = args.TotalBytesToReceive.ToString();
                    };
                    downloader.DownloadFileCompleted += (sender, args) =>
                    {
                        if (DownloadNext)
                        {
                            int index = -1;
                            if ((index = SongCollection.IndexOf(song)) != -1 && index + 1 < SongCollection.Count)
                            {
                                PlaylistDownloadCommand.Execute(SongCollection.ElementAt(index + 1));
                            }
                        }
                        else
                        {
                            BytesReceived       = "0";
                            TotalBytesToReceive = "0";
                        }
                    };
                    downloader.Get(SongTrackUrl, Path.Combine("music", FileUtils.GetSafeFileName(song.SongFileName)));
                });

                ListenCommand = new RelayCommand <Song>((song) =>
                {
                    SelectedSong = song;
                    if (string.IsNullOrWhiteSpace(SongTrackUrl))
                    {
                        return;
                    }
                    if (song.PlayStatus == PlayStatus.Play)
                    {
                        if (CurrentPlaySong != null && CurrentPlaySong != song)
                        {
                            audioPlayback.Stop();
                            CurrentPlaySong.PlayProgress = 0;
                            CurrentPlaySong.PlayStatus   = PlayStatus.Play;
                        }

                        audioPlayback.Load(SongTrackUrl);
                        audioPlayback.Play();

                        CurrentPlaySong = song;
                        NowPlaying      = string.Format("Now Playing {0} - {1}", song.Artists, song.Title);
                        timer.Enabled   = true;
                        timer.Start();
                        song.PlayProgress = 0;
                        song.PlayStatus   = PlayStatus.Stop;
                    }
                    else
                    {
                        audioPlayback.Stop();
                        NowPlaying        = "";
                        song.PlayStatus   = PlayStatus.Play;
                        song.PlayProgress = 0;
                        timer.Enabled     = false;
                        timer.Stop();
                    }
                });

                OpenUrlCommand = new RelayCommand <string>((link) =>
                {
                    System.Diagnostics.Process.Start(link);
                });

                CopyUrlCommand = new RelayCommand <string>((link) =>
                {
                    Clipboard.SetText(link);
                });

                WindowClosing = new RelayCommand(() =>
                {
                    Properties.Settings.Default.Save();
                });
            }
        }