예제 #1
0
        private async Task ImportFilesAsync()
        {
            try
            {
                List <string> tempFiles = null;

                await Task.Run(() =>
                {
                    lock (this.lockObject)
                    {
                        tempFiles = this.files.Select(item => (string)item.Clone()).ToList();
                        this.files.Clear(); // Clear the list
                    }

                    tempFiles.Sort(); // Sort the files alphabetically
                });

                List <PlayableTrack> tracks = await this.ProcessFilesAsync(tempFiles);

                PlayableTrack selectedTrack = tracks.First();

                LogClient.Info("Number of tracks to play = {0}", tracks.Count.ToString());

                if (tracks.Count > 0)
                {
                    LogClient.Info("Enqueuing {0} tracks.", tracks.Count.ToString());
                    this.TracksImported(tracks, selectedTrack);
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("Could not enqueue tracks. Exception: {0}", ex.Message);
            }
        }
예제 #2
0
        protected async virtual void RefreshCoverArtAsync(PlayableTrack track)
        {
            await Task.Run(async() =>
            {
                this.previousArtwork = this.artwork;

                // No track selected: clear cover art.
                if (track == null)
                {
                    this.ClearArtwork();
                    return;
                }

                // Try to find artwork
                byte[] artwork = null;

                try
                {
                    artwork = await this.metadataService.GetArtworkAsync(track.Path);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not get artwork for Track {0}. Exception: {1}", track.Path, ex.Message);
                }

                this.artwork = artwork;

                // Verify if the artwork changed
                if ((this.artwork != null & this.previousArtwork != null) && (this.artwork.LongLength == this.previousArtwork.LongLength))
                {
                    return;
                }
                else if (this.artwork == null & this.previousArtwork == null & this.CoverArtViewModel != null)
                {
                    return;
                }

                if (artwork != null)
                {
                    try
                    {
                        this.CoverArtViewModel = new CoverArtViewModel {
                            CoverArt = artwork
                        };
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error("Could not show file artwork for Track {0}. Exception: {1}", track.Path, ex.Message);
                        this.ClearArtwork();
                    }

                    return;
                }
                else
                {
                    this.ClearArtwork();
                    return;
                }
            });
        }
예제 #3
0
        public LyricsViewModel(IUnityContainer container, PlayableTrack track) : base(container)
        {
            this.track = track;

            // Dependency injection
            this.metadataService = container.Resolve <IMetadataService>();
            this.providerService = container.Resolve <IProviderService>();

            this.FontSize           = SettingsClient.Get <double>("Lyrics", "FontSize");
            this.AutomaticScrolling = SettingsClient.Get <bool>("Lyrics", "AutomaticScrolling");

            this.DecreaseFontSizeCommand = new DelegateCommand(() => { if (this.FontSize > 11)
                                                                       {
                                                                           this.FontSize--;
                                                                       }
                                                               });
            this.IncreaseFontSizeCommand = new DelegateCommand(() => { if (this.FontSize < 50)
                                                                       {
                                                                           this.FontSize++;
                                                                       }
                                                               });
            this.EditCommand       = new DelegateCommand(() => { this.IsEditing = true; });
            this.CancelEditCommand = new DelegateCommand(() =>
            {
                this.lyrics    = this.uneditedLyrics;
                this.IsEditing = false;
            });

            this.SaveCommand           = new DelegateCommand(async() => await this.SaveLyricsInAudioFileAsync());
            this.SaveIfNotEmptyCommand = new DelegateCommand(async() => await this.SaveLyricsInAudioFileAsync(), () => !string.IsNullOrWhiteSpace(this.lyrics.Text));

            this.SearchOnlineCommand = new DelegateCommand <string>((id) => this.SearchOnline(id));
        }
예제 #4
0
        public static bool FilterTracks(PlayableTrack track, string filter)
        {
            // Trim is required here, otherwise the filter might flip on the space at the beginning (and probably at the end)
            string[] pieces = filter.Trim().Split(Convert.ToChar(" "));

            // Just making sure that all fields are not Nothing
            if (track.TrackTitle == null)
            {
                track.TrackTitle = string.Empty;
            }
            if (track.ArtistName == null)
            {
                track.ArtistName = string.Empty;
            }
            if (track.AlbumTitle == null)
            {
                track.AlbumTitle = string.Empty;
            }
            if (track.FileName == null)
            {
                track.FileName = string.Empty;
            }
            if (track.Year == null)
            {
                track.Year = 0;
            }

            return(pieces.All((s) => track.TrackTitle.ToLower().Contains(s.ToLower()) | track.ArtistName.ToLower().Contains(s.ToLower()) | track.AlbumTitle.ToLower().Contains(s.ToLower()) | track.FileName.ToLower().Contains(s.ToLower()) | track.Year.ToString().Contains(s.ToLower())));
        }
        // Use this for initialization
        void Awake()
        {
            fc = FabulaContainer.Load(Path.Combine(Application.dataPath, "Scripts//CinemachineTimelineCode//FileIO_xml//fabula.xml"));

            timeline = (TimelineAsset)ScriptableObject.CreateInstance("TimelineAsset");

            director = GetComponent <PlayableDirector>();

            ctrack = timeline.CreateTrack <ControlTrack>(null, "control_track");
            ntrack = timeline.CreateTrack <PlayableTrack>(null, "nav_track");

            foreach (FabulaClip clip in fc.Clips)
            {
                if (clip.Type.Equals("animate"))
                {
                    populateAnimation(clip);
                }
                else if (clip.Type.Equals("navigate"))
                {
                    populateNavigation(clip);
                }
                else
                {
                    Debug.Log("What TYPE of clip is this?");
                }
            }
            director.Play(timeline);
        }
예제 #6
0
        private async Task <Tuple <List <PlayableTrack>, PlayableTrack> > ProcessFileAsync(string path)
        {
            var           tracks        = new List <PlayableTrack>();
            PlayableTrack selectedTrack = await this.CreateTrackAsync(path);

            tracks.Add(await this.CreateTrackAsync(path));

            return(new Tuple <List <PlayableTrack>, PlayableTrack>(tracks, selectedTrack));
        }
예제 #7
0
        public async Task EnqueueAsync(List <PlayableTrack> tracks, PlayableTrack track)
        {
            if (tracks == null || track == null)
            {
                return;
            }

            await this.EnqueueIfRequired(tracks);

            await this.PlaySelectedAsync(track);
        }
예제 #8
0
        public static async Task <PlayableTrack> Path2TrackAsync(string path, TrackStatistic savedTrackStatistic)
        {
            var returnTrack = new PlayableTrack();

            await Task.Run(() =>
            {
                var track          = new Track();
                var trackStatistic = new TrackStatistic();
                var album          = new Album();
                var artist         = new Artist();
                var genre          = new Genre();

                MetadataUtils.SplitMetadata(path, ref track, ref trackStatistic, ref album, ref artist, ref genre);

                returnTrack.Path        = track.Path;
                returnTrack.SafePath    = track.Path.ToSafePath();
                returnTrack.FileName    = track.FileName;
                returnTrack.MimeType    = track.MimeType;
                returnTrack.FileSize    = track.FileSize;
                returnTrack.BitRate     = track.BitRate;
                returnTrack.SampleRate  = track.SampleRate;
                returnTrack.TrackTitle  = track.TrackTitle;
                returnTrack.TrackNumber = track.TrackNumber;
                returnTrack.TrackCount  = track.TrackCount;
                returnTrack.DiscNumber  = track.DiscNumber;
                returnTrack.DiscCount   = track.DiscCount;
                returnTrack.Duration    = track.Duration;
                returnTrack.Year        = track.Year;
                returnTrack.HasLyrics   = track.HasLyrics;

                returnTrack.ArtistName = artist.ArtistName;

                returnTrack.GenreName = genre.GenreName;

                returnTrack.AlbumTitle  = album.AlbumTitle;
                returnTrack.AlbumArtist = album.AlbumArtist;
                returnTrack.AlbumYear   = album.Year;

                // If there is a saved TrackStatistic, used that one. Otherwise the
                // TrackStatistic from the file is used. That only contains rating.
                if (savedTrackStatistic != null)
                {
                    trackStatistic = savedTrackStatistic;
                }

                returnTrack.Rating         = trackStatistic.Rating;
                returnTrack.Love           = trackStatistic.Love;
                returnTrack.PlayCount      = trackStatistic.PlayCount;
                returnTrack.SkipCount      = trackStatistic.SkipCount;
                returnTrack.DateLastPlayed = trackStatistic.DateLastPlayed;
            });

            return(returnTrack);
        }
예제 #9
0
    void Start()
    {
        fdirector             = fabulaTimeline.GetComponent <PlayableDirector>();
        fdirector.initialTime = 0f;

        dc = DiscourseContainer.Load(Path.Combine(Application.dataPath, "Scripts//CinemachineTimelineCode//FileIO_xml//discourse.xml"));

        timeline = (TimelineAsset)ScriptableObject.CreateInstance("TimelineAsset");

        director = GetComponent <PlayableDirector>();

        main_camera_object = GameObject.Find("Main Camera");

        ftrack    = timeline.CreateTrack <CinemachineTrack>(null, "film_track");
        ctrack    = timeline.CreateTrack <ControlTrack>(null, "control_track");
        ntrack    = timeline.CreateTrack <PlayableTrack>(null, "nav_track");
        ptrack    = timeline.CreateTrack <PlayableTrack>(null, "timetravel_track");
        pos_track = timeline.CreateTrack <ControlTrack>(null, "pos_track");

        foreach (DiscourseClip clip in dc.Clips)
        {
            if (clip.Type.Equals("cam_custom"))
            {
                populateCustom(clip);
            }
            else if (clip.Type.Equals("nav_cam"))
            {
                populateNavCam(clip);
            }
            else if (clip.Type.Equals("nav_virtual"))
            {
                populateNavVirtual(clip);
            }
            // cam_timeline cannot time travel
            else if (clip.Type.Equals("cam_timeline"))
            {
                populateCamObject(clip);
            }
            else if (clip.Type.Equals("cntrl_timeline"))
            {
                populateCtrlObject(clip);
                if (clip.fabulaStart >= 0f)
                {
                    addTimeTravel(clip);
                }
            }
            else
            {
                Debug.Log("What TYPE of discourse clip is this?");
            }
        }
        director.SetGenericBinding(ftrack, main_camera_object);
        director.Play(timeline);
    }
예제 #10
0
        public async Task EnqueueAsync(List <PlayableTrack> tracks, PlayableTrack track)
        {
            if (tracks == null || track == null)
            {
                return;
            }

            await this.EnqueueIfDifferent(tracks, this.shuffle);

            await this.PlaySelectedAsync(track);
        }
        private async void RefreshPlaybackInfoAsync(PlayableTrack track, bool allowRefreshingCurrentTrack)
        {
            await Task.Run(() =>
            {
                this.previousTrack = this.track;

                // No track selected: clear playback info.
                if (track == null)
                {
                    this.ClearPlaybackInfo();
                    return;
                }

                this.track = track;

                // The track didn't change: leave the previous playback info.
                if (!allowRefreshingCurrentTrack & this.track.Equals(this.previousTrack))
                {
                    return;
                }

                // The track changed: we need to show new playback info.
                try
                {
                    string year = string.Empty;

                    if (track.Year != null && track.Year > 0)
                    {
                        year = track.Year.ToString();
                    }

                    this.PlaybackInfoViewModel = new PlaybackInfoViewModel
                    {
                        Title       = string.IsNullOrEmpty(track.TrackTitle) ? track.FileName : track.TrackTitle,
                        Artist      = track.ArtistName,
                        Album       = track.AlbumTitle,
                        Year        = year,
                        CurrentTime = FormatUtils.FormatTime(new TimeSpan(0)),
                        TotalTime   = FormatUtils.FormatTime(new TimeSpan(0))
                    };
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not show playback information for Track {0}. Exception: {1}", track.Path, ex.Message);
                    this.ClearPlaybackInfo();
                }

                this.RaisePropertyChanged(nameof(Rating));
                this.RaisePropertyChanged(nameof(Love));
                this.UpdateTime();
            });
        }
예제 #12
0
        private void ClearPlaybackInfo()
        {
            this.PlaybackInfoViewModel = new PlaybackInfoViewModel
            {
                Title       = string.Empty,
                Artist      = string.Empty,
                Album       = string.Empty,
                Year        = string.Empty,
                CurrentTime = string.Empty,
                TotalTime   = string.Empty
            };

            this.track = null;
        }
예제 #13
0
 public async Task StopIfPlayingAsync(PlayableTrack track)
 {
     if (track.Equals(this.CurrentTrack.Value))
     {
         if (this.Queue.Count == 1)
         {
             this.Stop();
         }
         else
         {
             await this.PlayNextAsync();
         }
     }
 }
예제 #14
0
        private async Task ImportFilesAsync()
        {
            try
            {
                List <string> tempFiles = null;

                await Task.Run(() =>
                {
                    lock (this.lockObject)
                    {
                        tempFiles = this.files.Select(item => (string)item.Clone()).ToList();
                        this.files.Clear(); // Clear the list
                    }

                    tempFiles.Sort(); // Sort the files alphabetically
                });

                List <PlayableTrack> tracks = await this.ProcessFilesAsync(tempFiles);

                PlayableTrack selectedTrack = null;

                if (tempFiles.Count.Equals(1) && FileFormats.IsSupportedAudioFile(tempFiles.First()))
                {
                    // If there is only 1 file and it's a supported audio format, we do something special.
                    Tuple <List <PlayableTrack>, PlayableTrack> processedTracks = await this.ProcessFileAsync(tempFiles.First());

                    tracks        = processedTracks.Item1;
                    selectedTrack = processedTracks.Item2;
                }
                else
                {
                    tracks = await this.ProcessFilesAsync(tempFiles);

                    selectedTrack = tracks.First();
                }

                LogClient.Info("Number of tracks to play = {0}", tracks.Count.ToString());

                if (tracks.Count > 0)
                {
                    LogClient.Info("Enqueuing {0} tracks.", tracks.Count.ToString());
                    this.TracksImported(tracks, selectedTrack);
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("Could not enqueue tracks. Exception: {0}", ex.Message);
            }
        }
        public LyricsControlViewModel(IUnityContainer container, IMetadataService metadataService, IPlaybackService playbackService, EventAggregator eventAggregator)
        {
            this.container       = container;
            this.metadataService = metadataService;
            this.playbackService = playbackService;
            this.eventAggregator = eventAggregator;

            this.highlightTimer.Interval = this.highlightTimerIntervalMilliseconds;
            this.highlightTimer.Elapsed += HighlightTimer_Elapsed;

            this.updateLyricsAfterEditingTimer.Interval = this.updateLyricsAfterEditingTimerIntervalMilliseconds;
            this.updateLyricsAfterEditingTimer.Elapsed += UpdateLyricsAfterEditingTimer_Elapsed;

            this.refreshTimer.Interval = this.refreshTimerIntervalMilliseconds;
            this.refreshTimer.Elapsed += RefreshTimer_Elapsed;

            this.playbackService.PlaybackPaused  += (_, __) => this.highlightTimer.Stop();
            this.playbackService.PlaybackResumed += (_, __) => this.highlightTimer.Start();

            this.metadataService.MetadataChanged += (_) => this.RefreshLyricsAsync(this.playbackService.CurrentTrack.Value);

            this.eventAggregator.GetEvent <SettingDownloadLyricsChanged>().Subscribe(isDownloadLyricsEnabled => { if (isDownloadLyricsEnabled)
                                                                                                                  {
                                                                                                                      this.RefreshLyricsAsync(this.playbackService.CurrentTrack.Value);
                                                                                                                  }
                                                                                     });

            this.RefreshLyricsCommand = new DelegateCommand(() => this.RefreshLyricsAsync(this.playbackService.CurrentTrack.Value), () => !this.IsDownloadingLyrics);
            ApplicationCommands.RefreshLyricsCommand.RegisterCommand(this.RefreshLyricsCommand);

            this.playbackService.PlaybackSuccess += (isPlayingPreviousTrack) =>
            {
                this.ContentSlideInFrom = isPlayingPreviousTrack ? -30 : 30;

                if (this.previousTrack == null || !this.playbackService.CurrentTrack.Equals(this.previousTrack))
                {
                    this.refreshTimer.Stop();
                    this.refreshTimer.Start();
                    this.previousTrack = this.playbackService.CurrentTrack.Value;
                }
            };

            this.ClearLyrics(); // Makes sure the loading animation can be shown even at first start
            this.RefreshLyricsAsync(this.playbackService.CurrentTrack.Value);
            if (this.playbackService.HasCurrentTrack)
            {
                this.previousTrack = this.playbackService.CurrentTrack.Value;
            }
        }
예제 #16
0
        private bool UpdateTrackPlaybackInfo(PlayableTrack track, IFileMetadata fileMetadata)
        {
            bool isDisplayedPlaybackInfoChanged = false;

            try
            {
                // Only update the properties that are displayed on Now Playing screens
                if (fileMetadata.Title.IsValueChanged)
                {
                    track.TrackTitle = fileMetadata.Title.Value;
                    isDisplayedPlaybackInfoChanged = true;
                }

                if (fileMetadata.Artists.IsValueChanged)
                {
                    track.ArtistName = fileMetadata.Artists.Values.FirstOrDefault();
                    isDisplayedPlaybackInfoChanged = true;
                }

                if (fileMetadata.Year.IsValueChanged)
                {
                    track.Year = fileMetadata.Year.Value.SafeConvertToLong();
                    isDisplayedPlaybackInfoChanged = true;
                }

                if (fileMetadata.Album.IsValueChanged)
                {
                    track.AlbumTitle = fileMetadata.Album.Value;
                    isDisplayedPlaybackInfoChanged = true;
                }

                if (fileMetadata.ArtworkData.IsValueChanged)
                {
                    isDisplayedPlaybackInfoChanged = true;
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("Could not update the track metadata. Exception: {0}", ex.Message);
            }

            return(isDisplayedPlaybackInfoChanged);
        }
예제 #17
0
        public async Task <PlayableTrack> CreateTrackAsync(string path)
        {
            var returnTrack = new PlayableTrack();

            try
            {
                var savedTrackStatistic = await this.trackStatisticRepository.GetTrackStatisticAsync(path);

                returnTrack = await MetadataUtils.Path2TrackAsync(path, savedTrackStatistic);
            }
            catch (Exception ex)
            {
                // Make sure the file can be opened by creating a Track with some default values
                returnTrack = PlayableTrack.CreateDefault(path);
                LogClient.Error("Error while creating Track from file '{0}'. Creating default track. Exception: {1}", path, ex.Message);
            }

            return(returnTrack);
        }
예제 #18
0
        public async Task <bool> SendTrackLoveAsync(PlayableTrack track, bool love)
        {
            bool isSuccess = false;

            // We can't send track love for an unknown track
            if (track.ArtistName == Defaults.UnknownArtistText | string.IsNullOrEmpty(track.TrackTitle))
            {
                return(false);
            }

            if (this.SignInState == SignInState.SignedIn)
            {
                if (love)
                {
                    try
                    {
                        isSuccess = await LastfmApi.TrackLove(this.sessionKey, track.ArtistName, track.TrackTitle);
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error("Could not send track.love to Last.fm. Exception: {0}", ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        isSuccess = await LastfmApi.TrackUnlove(this.sessionKey, track.ArtistName, track.TrackTitle);
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error("Could not send track.unlove to Last.fm. Exception: {0}", ex.Message);
                    }
                }
            }

            return(isSuccess);
        }
예제 #19
0
        private async Task <Tuple <List <PlayableTrack>, PlayableTrack> > ProcessFileAsync(string path)
        {
            var           tracks        = new List <PlayableTrack>();
            PlayableTrack selectedTrack = await this.CreateTrackAsync(path);

            if (SettingsClient.Get <bool>("Behaviour", "EnqueueOtherFilesInFolder"))
            {
                // Get all files in the current (top) directory
                List <string> scannedPaths = this.ProcessDirectory(Path.GetDirectoryName(path), SearchOption.TopDirectoryOnly);

                // Add all files from that directory
                foreach (string scannedPath in scannedPaths)
                {
                    tracks.Add(await this.CreateTrackAsync(scannedPath));
                }
            }
            else
            {
                tracks.Add(await this.CreateTrackAsync(path));
            }

            return(new Tuple <List <PlayableTrack>, PlayableTrack>(tracks, selectedTrack));
        }
예제 #20
0
        public async Task <PlayableTrack> CreateTrackAsync(string path)
        {
            var returnTrack = new PlayableTrack();

            try
            {
                var savedTrackStatistic = await this.trackStatisticRepository.GetTrackStatisticAsync(path);

                returnTrack = await MetadataUtils.Path2TrackAsync(this.fileMetadataFactory.Create(path), savedTrackStatistic);
            }
            catch (Exception ex)
            {
                // Make sure the file can be opened by creating a Track with some default values
                returnTrack = PlayableTrack.CreateDefault(path);
                LogClient.Error("Error while creating Track from file '{0}'. Creating default track. Exception: {1}", path, ex.Message);
            }

            returnTrack.ArtistName  = returnTrack.ArtistName.Replace(Defaults.UnknownArtistText, info.UnknownArtistText);
            returnTrack.AlbumArtist = returnTrack.AlbumArtist.Replace(Defaults.UnknownArtistText, info.UnknownArtistText);
            returnTrack.AlbumTitle  = returnTrack.AlbumTitle.Replace(Defaults.UnknownAlbumText, info.UnknownAlbumText);
            returnTrack.GenreName   = returnTrack.GenreName.Replace(Defaults.UnknownGenreText, info.UnknownGenreText);

            return(returnTrack);
        }
예제 #21
0
        private async void RefreshLyricsAsync(PlayableTrack track)
        {
            if (!this.nowPlayingIsSelected || !this.lyricsScreenIsActive)
            {
                return;
            }
            if (track == null)
            {
                return;
            }
            if (this.previousTrack != null && this.previousTrack.Equals(track))
            {
                return;
            }

            this.previousTrack = track;

            this.StopHighlighting();

            FileMetadata fmd = await this.metadataService.GetFileMetadataAsync(track.Path);

            await Task.Run(() =>
            {
                // If we're in editing mode, delay changing the lyrics.
                if (this.LyricsViewModel != null && this.LyricsViewModel.IsEditing)
                {
                    this.updateLyricsAfterEditingTimer.Start();
                    return;
                }

                // No FileMetadata available: clear the lyrics.
                if (fmd == null)
                {
                    this.ClearLyrics();
                    return;
                }
            });

            try
            {
                Lyrics lyrics             = null;
                bool   mustDownloadLyrics = false;

                await Task.Run(() =>
                {
                    lyrics = new Lyrics(fmd != null && fmd.Lyrics.Value != null ? fmd.Lyrics.Value : String.Empty, string.Empty);

                    // If the file has no lyrics, and the user enabled automatic download of lyrics, indicate that we need to try to download.
                    if (!lyrics.HasText)
                    {
                        if (SettingsClient.Get <bool>("Lyrics", "DownloadLyrics"))
                        {
                            string artist = fmd.Artists != null && fmd.Artists.Values != null && fmd.Artists.Values.Length > 0 ? fmd.Artists.Values[0] : string.Empty;
                            string title  = fmd.Title != null && fmd.Title.Value != null ? fmd.Title.Value : string.Empty;

                            if (!string.IsNullOrWhiteSpace(artist) & !string.IsNullOrWhiteSpace(title))
                            {
                                mustDownloadLyrics = true;
                            }
                        }
                    }
                });

                // No lyrics were found in the file: try to download.
                if (mustDownloadLyrics)
                {
                    this.IsDownloadingLyrics = true;

                    try
                    {
                        var factory = new LyricsFactory();
                        lyrics = await factory.GetLyricsAsync(fmd.Artists.Values[0], fmd.Title.Value);
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error("Could not get lyrics online {0}. Exception: {1}", track.Path, ex.Message);
                    }

                    this.IsDownloadingLyrics = false;
                }

                await Task.Run(() =>
                {
                    this.LyricsViewModel = new LyricsViewModel(container, track, metadataService);
                    this.LyricsViewModel.SetLyrics(lyrics);
                });
            }
            catch (Exception ex)
            {
                this.IsDownloadingLyrics = false;
                LogClient.Error("Could not show lyrics for Track {0}. Exception: {1}", track.Path, ex.Message);
                this.ClearLyrics();
                return;
            }

            this.StartHighlighting();
        }
예제 #22
0
        private async Task ShowArtistInfoAsync(PlayableTrack track, bool forceReload)
        {
            this.previousArtist = this.artist;

            // User doesn't want to download artist info, or no track is selected.
            if (!SettingsClient.Get <bool>("Lastfm", "DownloadArtistInformation") || track == null)
            {
                this.ArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>();
                this.artist = null;
                return;
            }

            // Artist name is unknown
            if (track.ArtistName == Defaults.UnknownArtistText)
            {
                ArtistInfoViewModel localArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>();
                await localArtistInfoViewModel.SetLastFmArtistAsync(new Common.Api.Lastfm.Artist {
                    Name = Defaults.UnknownArtistText
                });

                this.ArtistInfoViewModel = localArtistInfoViewModel;
                this.artist = null;
                return;
            }

            this.artist = new Common.Database.Entities.Artist
            {
                ArtistName = track.ArtistName
            };

            // The artist didn't change: leave the previous artist info.
            if (this.artist.Equals(this.previousArtist) & !forceReload)
            {
                return;
            }

            // The artist changed: we need to show new artist info.
            string artworkPath = string.Empty;

            this.IsBusy = true;

            try
            {
                Common.Api.Lastfm.Artist lfmArtist = await LastfmApi.ArtistGetInfo(track.ArtistName, true, ResourceUtils.GetString("Language_ISO639-1"));

                if (lfmArtist != null)
                {
                    if (string.IsNullOrEmpty(lfmArtist.Biography.Content))
                    {
                        // In case there is no localized Biography, get the English one.
                        lfmArtist = await LastfmApi.ArtistGetInfo(track.ArtistName, true, "EN");
                    }

                    if (lfmArtist != null)
                    {
                        ArtistInfoViewModel localArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>();
                        await localArtistInfoViewModel.SetLastFmArtistAsync(lfmArtist);

                        this.ArtistInfoViewModel = localArtistInfoViewModel;
                    }
                    else
                    {
                        throw new Exception("lfmArtist == null");
                    }
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("Could not show artist information for Track {0}. Exception: {1}", track.Path, ex.Message);
                this.ArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>();
                this.artist = null;
            }

            this.IsBusy = false;
        }
예제 #23
0
 public async Task PlaySelectedAsync(PlayableTrack track)
 {
     await this.TryPlayAsync(new KeyValuePair <string, PlayableTrack>(null, track));
 }
예제 #24
0
        public NotificationWindow(PlayableTrack track, byte[] artworkData, NotificationPosition position, bool showControls, int maxSecondsVisible) : base()
        {
            this.InitializeComponent();

            this.maxSecondsVisible = maxSecondsVisible;

            int notificationHeight = 66 + 2 * this.notificationShadowSize;
            int notificationWidth  = 286 + 2 * this.notificationShadowSize;

            if (showControls)
            {
                notificationHeight           += 40;
                notificationWidth            += 90;
                this.ControlsPanel.Visibility = Visibility.Visible;
                this.VolumePanel.Visibility   = Visibility.Visible;
            }
            else
            {
                this.ControlsPanel.Visibility = Visibility.Collapsed;
                this.VolumePanel.Visibility   = Visibility.Collapsed;
            }

            if (track != null)
            {
                this.TextBoxTitle.Text  = string.IsNullOrEmpty(track.TrackTitle) ? track.FileName : track.TrackTitle;
                this.TextBoxArtist.Text = track.ArtistName;
            }
            else
            {
                this.TextBoxTitle.Text  = ResourceUtils.GetStringResource("Language_Title");
                this.TextBoxArtist.Text = ResourceUtils.GetStringResource("Language_Artist");
            }

            this.ToolTipTitle.Text  = this.TextBoxTitle.Text;
            this.ToolTipArtist.Text = this.TextBoxArtist.Text;

            if (artworkData != null)
            {
                try
                {
                    // Width and Height are 300px. They need to be big enough, otherwise the picture is blurry
                    this.CoverPicture.Source = ImageUtils.ByteToBitmapImage(artworkData, 300, 300, 0);
                    this.CloseBorder.Opacity = 1.0;
                }
                catch (Exception)
                {
                    // Swallow
                }
            }
            else
            {
                this.CloseBorder.Opacity = 0.4;
            }


            Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
            {
                Rect desktopWorkingArea = System.Windows.SystemParameters.WorkArea;

                // First, set the position
                switch (position)
                {
                case NotificationPosition.BottomLeft:
                    // Bottom left
                    this.Left = desktopWorkingArea.Left + this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Bottom - notificationHeight - this.notificationMarginFromScreen;
                    break;

                case NotificationPosition.TopLeft:
                    // Top left
                    this.Left = desktopWorkingArea.Left + this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Top + this.notificationMarginFromScreen;
                    break;

                case NotificationPosition.TopRight:
                    // Top right
                    this.Left = desktopWorkingArea.Right - notificationWidth - this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Top + this.notificationMarginFromScreen;
                    break;

                case NotificationPosition.BottomRight:
                    // Bottom right
                    this.Left = desktopWorkingArea.Right - notificationWidth - this.notificationMarginFromScreen;
                    this.Top  = desktopWorkingArea.Bottom - notificationHeight - this.notificationMarginFromScreen;
                    break;

                default:
                    break;
                }

                // After setting the position, set the size. The original size op 0px*0px prevents
                // flicker when displaying the popup. Because it briefly appears in the top left
                // corner before getting its desired position.
                this.Width               = notificationWidth;
                this.Height              = notificationHeight;
                this.CoverPicture.Width  = notificationHeight - 2 * this.notificationShadowSize;
                this.CoverPicture.Height = notificationHeight - 2 * this.notificationShadowSize;
                this.CoverTile.Width     = notificationHeight - 2 * this.notificationShadowSize;
                this.CoverTile.Height    = notificationHeight - 2 * this.notificationShadowSize;
            }));

            this.hideTimer.Interval  = TimeSpan.FromSeconds(1);
            this.closeTimer.Interval = TimeSpan.FromSeconds(1);
            this.hideTimer.Tick     += new EventHandler(HideTimer_Tick);
            this.closeTimer.Tick    += new EventHandler(CloseTimer_Tick);
        }
예제 #25
0
    public override void ExecuteState(StateMachine stateMachine, IState prevState, object param1, object param2)
    {
        base.ExecuteState(stateMachine, prevState, param1, param2);

        mCurrSkillID = (int)param1;
        mChangeState = false;

        mSkillInfo = SkillConfig.singleton.GetSkillInfo(mCurrSkillID);
        if (mSkillInfo == null || mSkillInfo.mTimeline == null)
        {
            return;
        }
        mTargetRole = mRole.mRoleData.GetTargetRole();

        if (Skill.ExecuteSkill(mRole, mTargetRole, mSkillInfo))
        {
            mChangeState = false;
        }
        else
        {
            StateComplete();
            return;
        }

        // 获取timeline
        mDirector = mSkillInfo.mTimeline.GetComponent <PlayableDirector>();
        mDirector.Stop();

        // 取出timeline 左边的名字进行绑定右边的资源
        foreach (PlayableBinding bind in mDirector.playableAsset.outputs)
        {
            if (bind.streamName == "Self")
            {
                AnimationTrack animationTrack = bind.sourceObject as AnimationTrack;
                mDuringTime = (float)animationTrack.duration;
                mBeginTime  = Time.fixedTime;
                mDirector.SetGenericBinding(bind.sourceObject, mAnimator);
            }
            else if (bind.streamName == "Target")
            {
                mDirector.SetGenericBinding(bind.sourceObject, mTargetRole.mAnimator);

                mRole.transform.position = -mRole.transform.forward * mSkillInfo.mAtkDistance + mTargetRole.transform.position;

                mRole.mRoleData.SetForward(mTargetRole.transform.position, mRole.transform.position);
                mRole.transform.rotation = Quaternion.LookRotation(mRole.mRoleData.GetForward());

                mTargetRole.mRoleData.SetForward(mRole.transform.position, mTargetRole.transform.position);
                mTargetRole.transform.rotation = Quaternion.LookRotation(mTargetRole.mRoleData.GetForward());
            }
            else if (bind.streamName == "SelfEffect")
            {
                mDirector.SetGenericBinding(bind.sourceObject, mSkillInfo.mSelfEffect);
            }
            else if (bind.streamName == "TargetEffect")
            {
                mDirector.SetGenericBinding(bind.sourceObject, mSkillInfo.mTargetEffect);
            }
            else if (bind.streamName == "Control Track")
            {
                ControlTrack ct = bind.sourceObject as ControlTrack;
                foreach (var clip in ct.GetClips())
                {
                    ControlPlayableAsset playableAsset = clip.asset as ControlPlayableAsset;
                    mDirector.SetReferenceValue(playableAsset.sourceGameObject.exposedName, mRole.gameObject);
                }
            }
            else if (bind.streamName == "Playable Track")
            {
                PlayableTrack ct = bind.sourceObject as PlayableTrack;
                foreach (TimelineClip clip in ct.GetClips())
                {
                    PlayableAssetEx playableAsset = clip.asset as PlayableAssetEx;
                    if (playableAsset)
                    {
                        // 1.自定义脚本获取绑定 自定义的变量
                        playableAsset.mParamAttackTL = this;
                    }
                }
            }
        }

        mDirector.Play(); // 播放timeline
    }
예제 #26
0
 private void ClearLyrics(PlayableTrack track)
 {
     this.LyricsViewModel = new LyricsViewModel(this.container, track);
 }
    // Use this for initialization
    void Awake()
    {
        List <List <string> > clipList = readFabula();

        foreach (List <string> clipItem in clipList)
        {
            Debug.Log("Clip:");
            foreach (string item in clipItem)
            {
                Debug.Log(item);
            }
        }

        timeline = (TimelineAsset)ScriptableObject.CreateInstance("TimelineAsset");

        PlayableDirector director = GetComponent <PlayableDirector>();

        TrackAsset    ctrack = timeline.CreateTrack <ControlTrack>(null, "control_track");
        PlayableTrack ntrack = timeline.CreateTrack <PlayableTrack>(null, "nav_track");

        foreach (List <string> clipitem_list in clipList)
        {
            string name = clipitem_list[0];
            string type = clipitem_list[1];

            if (type.Equals("animate"))
            {
                float  start         = float.Parse(clipitem_list[2]);
                float  dur           = float.Parse(clipitem_list[3]);
                string anim_location = clipitem_list[4];
                string animation_obj = clipitem_list[5];

                start_pos = GameObject.Find(anim_location).transform;
                var lerp_clip = ntrack.CreateClip <LerpMoveObjectAsset>();
                var lerpclip  = lerp_clip.asset as LerpMoveObjectAsset;

                var clip = ctrack.CreateDefaultClip();
                clip.start       = start;
                clip.duration    = dur;
                clip.displayName = name;
                animTimeline     = GameObject.Find(animation_obj);
                var controlAnim = clip.asset as ControlPlayableAsset;
                anim_transform = animTimeline.transform;
                anim_loc       = anim_transform.position;
                anim_rot       = anim_transform.rotation;

                setClipOffset(animTimeline, anim_loc, anim_rot);
                //List<TimelineClip> lerp_clips = target_lerp_track.GetClips().ToList();

                lerpclip.ObjectToMove.exposedName = UnityEditor.GUID.Generate().ToString();
                lerpclip.LerpMoveTo.exposedName   = UnityEditor.GUID.Generate().ToString();
                //director.SetReferenceValue(lerpclip.ObjectToMove.exposedName, movingObj);
                director.SetReferenceValue(lerpclip.LerpMoveTo.exposedName, start_pos);

                // Set control clip to be on fabula timeline
                controlAnim.sourceGameObject.exposedName = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(controlAnim.sourceGameObject.exposedName, animTimeline);
            }
            else if (type.Equals("navigate"))
            {
                float  start          = float.Parse(clipitem_list[2]);
                float  dur            = float.Parse(clipitem_list[3]);
                string start_location = clipitem_list[4];
                string end_location   = clipitem_list[5];
                string agent          = clipitem_list[6];
                float  speed          = float.Parse(clipitem_list[7]);

                //ntrack
                ////var clip = ctrack.CreateDefaultClip();
                var lerp_clip = ntrack.CreateClip <LerpMoveObjectAsset>();
                var clip      = ntrack.CreateClip <SetAgentTargetAsset>();


                //var navclip = clip.asset as SetAgentTargetAsset;
                lerp_clip.start       = start;
                lerp_clip.duration    = .05f;
                lerp_clip.displayName = "lerp";

                clip.start       = start + .05f;
                clip.duration    = dur - .05f;
                clip.displayName = name;
                GameObject   movingObj       = GameObject.Find(agent);
                NavMeshAgent navigatingAgent = movingObj.GetComponent <NavMeshAgent>();

                start_pos = GameObject.Find(start_location).transform;
                Transform end_pos = GameObject.Find(end_location).transform;

                var navclip  = clip.asset as SetAgentTargetAsset;
                var lerpclip = lerp_clip.asset as LerpMoveObjectAsset;



                navclip.AgentSpeed = speed;
                //navclip.Agent = navigatingAgent as NavMeshAgent;

                navclip.Target.exposedName = UnityEditor.GUID.Generate().ToString();
                navclip.Agent.exposedName  = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(navclip.Agent.exposedName, navigatingAgent);
                director.SetReferenceValue(navclip.Target.exposedName, end_pos);
                lerpclip.ObjectToMove.exposedName = UnityEditor.GUID.Generate().ToString();
                lerpclip.LerpMoveTo.exposedName   = UnityEditor.GUID.Generate().ToString();
                director.SetReferenceValue(lerpclip.ObjectToMove.exposedName, movingObj);
                director.SetReferenceValue(lerpclip.LerpMoveTo.exposedName, start_pos);
            }
            else
            {
                Debug.Log("incorrect clip type");
            }
        }

        director.Play(timeline);
    }
예제 #28
0
 public LyricsViewModel(IContainerProvider container, PlayableTrack track) : this(container)
 {
     this.track = track;
 }
예제 #29
0
        private void BindData(Animator attacker, Animator target)
        {
            PlayableTrack playableTrack =
                (PlayableTrack)playableBindingDir["Event Track".GetHashCode()].sourceObject;


            foreach (var clips in playableTrack.GetClips())
            {
                object asset = clips.asset;
                if (!(asset is ShowEffectAsset))
                {
                    continue;
                }

                ShowEffectAsset showEffectAsset = (ShowEffectAsset)asset;
                showEffectAsset.effectEventReference = new ExposedReference <EffectEvent>
                {
                    defaultValue = monoBehaviour.GetComponent <EffectEvent>()
                };
                showEffectAsset.eventName = "FrontStabEffect";
            }

            playableTrack = (PlayableTrack)playableBindingDir["Character State Lock".GetHashCode()].sourceObject;

            foreach (var clips in playableTrack.GetClips())
            {
                if (!(clips.asset is CharacterStateLockAsset))
                {
                    continue;
                }


                CharacterStateLockAsset characterStateLockAsset = (CharacterStateLockAsset)clips.asset;

                characterStateLockAsset.attackerAnimator = new ExposedReference <Animator> {
                    defaultValue = attacker
                };
                characterStateLockAsset.receiverAnimator = new ExposedReference <Animator> {
                    defaultValue = target
                };
            }

            playableTrack = (PlayableTrack)playableBindingDir["Damageable Track".GetHashCode()].sourceObject;
            foreach (var clips in playableTrack.GetClips())
            {
                if (!(clips.asset is DamageableAsset))
                {
                    continue;
                }


                DamageableAsset damageableAsset = (DamageableAsset)clips.asset;

                damageableAsset.damageable =
                    new ExposedReference <Damageable> {
                    defaultValue = target.GetComponent <Damageable>()
                };

                DamageData data = new DamageData()
                {
                    attacker  = attacker.gameObject,
                    damage    = monoBehaviour.weapon.damage * 2,
                    damagePos = monoBehaviour.weapon.transform.position,
                    direction = target.transform.position - attacker.transform.position
                };

                damageableAsset.data = data;
            }
        }
예제 #30
0
        private async void RefreshLyricsAsync(PlayableTrack track)
        {
            if (!this.nowPlayingIsSelected || !this.lyricsScreenIsActive)
            {
                return;
            }
            if (track == null)
            {
                return;
            }
            if (this.previousTrack != null && this.previousTrack.Equals(track))
            {
                return;
            }

            this.previousTrack = track;

            this.StopHighlighting();

            FileMetadata fmd = await this.metadataService.GetFileMetadataAsync(track.Path);

            await Task.Run(() =>
            {
                // If we're in editing mode, delay changing the lyrics.
                if (this.LyricsViewModel != null && this.LyricsViewModel.IsEditing)
                {
                    this.updateLyricsAfterEditingTimer.Start();
                    return;
                }

                // No FileMetadata available: clear the lyrics.
                if (fmd == null)
                {
                    this.ClearLyrics();
                    return;
                }
            });

            try
            {
                Lyrics lyrics             = null;
                bool   mustDownloadLyrics = false;

                await Task.Run(async() =>
                {
                    // Try to get lyrics from the audio file
                    lyrics            = new Lyrics(fmd != null && fmd.Lyrics.Value != null ? fmd.Lyrics.Value : String.Empty, string.Empty);
                    lyrics.SourceType = SourceTypeEnum.Audio;

                    // If the audio file has no lyrics, try to find lyrics in a local lyrics file.
                    if (!lyrics.HasText)
                    {
                        var lrcFile = Path.Combine(Path.GetDirectoryName(fmd.Path), Path.GetFileNameWithoutExtension(fmd.Path) + FileFormats.LRC);

                        if (File.Exists(lrcFile))
                        {
                            using (var fs = new FileStream(lrcFile, FileMode.Open, FileAccess.Read))
                            {
                                using (var sr = new StreamReader(fs, Encoding.Default))
                                {
                                    lyrics = new Lyrics(await sr.ReadToEndAsync(), String.Empty);
                                    if (lyrics.HasText)
                                    {
                                        lyrics.SourceType = SourceTypeEnum.Lrc;
                                        return;
                                    }
                                }
                            }
                        }

                        // If we still don't have lyrics and the user enabled automatic download of lyrics: try to download them online.
                        if (SettingsClient.Get <bool>("Lyrics", "DownloadLyrics"))
                        {
                            string artist = fmd.Artists != null && fmd.Artists.Values != null && fmd.Artists.Values.Length > 0 ? fmd.Artists.Values[0] : string.Empty;
                            string title  = fmd.Title != null && fmd.Title.Value != null ? fmd.Title.Value : string.Empty;

                            if (!string.IsNullOrWhiteSpace(artist) & !string.IsNullOrWhiteSpace(title))
                            {
                                mustDownloadLyrics = true;
                            }
                        }
                    }
                });

                // No lyrics were found in the file: try to download.
                if (mustDownloadLyrics)
                {
                    this.IsDownloadingLyrics = true;

                    try
                    {
                        var factory = new LyricsFactory();
                        lyrics = await factory.GetLyricsAsync(fmd.Artists.Values[0], fmd.Title.Value);

                        lyrics.SourceType = SourceTypeEnum.Online;
                    }
                    catch (Exception ex)
                    {
                        CoreLogger.Current.Error("Could not get lyrics online {0}. Exception: {1}", track.Path, ex.Message);
                    }

                    this.IsDownloadingLyrics = false;
                }

                await Task.Run(() =>
                {
                    this.LyricsViewModel = new LyricsViewModel(container, track);
                    this.LyricsViewModel.SetLyrics(lyrics);
                });
            }
            catch (Exception ex)
            {
                this.IsDownloadingLyrics = false;
                CoreLogger.Current.Error("Could not show lyrics for Track {0}. Exception: {1}", track.Path, ex.Message);
                this.ClearLyrics();
                return;
            }

            this.StartHighlighting();
        }