Example #1
0
 public void Save()
 {
     try
     {
         var fileName = Path.Combine(TinyIoCContainer.Current.Resolve <AppHelper>().ApplicationPath, SettingsFileName);
         LogHost.Default.Info("saving player settings to {0}", fileName);
         var settingsAsJson = JsonConvert.SerializeObject(this, Formatting.Indented);
         QuickIOFile.WriteAllText(fileName, settingsAsJson);
     }
     catch (Exception exception)
     {
         LogHost.Default.Error("could not save player settings", exception);
     }
 }
Example #2
0
        public BitmapImage GetImageFromFile(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName) || !QuickIOFile.Exists(fileName))
            {
                return(null);
            }

            // try getting the cover by picture tag
            var resolvedImage = GetImageFromPictureTag(fileName);

            // if no cover was found try getting the cover from disk
            resolvedImage = resolvedImage ?? GetImageFromDirectory(fileName);

            return(resolvedImage);
        }
Example #3
0
 public static bool Save(PlayList playList)
 {
     try
     {
         var fileName = Path.Combine(TinyIoCContainer.Current.Resolve <AppHelper>().ApplicationPath, PlayListFileName);
         LogHost.Default.Info("try saving play list to {0}", fileName);
         using (StreamWriter file = QuickIOFile.CreateText(fileName))
         {
             file.AutoFlush = true;
             var serializer = new JsonSerializer();
             serializer.Serialize(file, playList);
         }
         LogHost.Default.Info("play list saved with {0} files", playList.Files.Count);
     }
     catch (Exception exception)
     {
         LogHost.Default.Error("could not save play list", exception);
         return(false);
     }
     return(true);
 }
Example #4
0
 public static async Task <PlayList> LoadAsync()
 {
     try
     {
         var fileName = Path.Combine(TinyIoCContainer.Current.Resolve <AppHelper>().ApplicationPath, PlayListFileName);
         if (!QuickIOFile.Exists(fileName))
         {
             return(null);
         }
         LogHost.Default.Info("try loading play list from {0}", fileName);
         using (StreamReader file = await Task.Run(() => QuickIOFile.OpenText(fileName)))
         {
             var serializer = new JsonSerializer();
             return((PlayList)serializer.Deserialize(file, typeof(PlayList)));
         }
     }
     catch (Exception ex)
     {
         LogHost.Default.ErrorException("could not load play list", ex);
     }
     return(null);
 }
Example #5
0
        public static PlayerSettings Update(this PlayerSettings settings)
        {
            try
            {
                var fileName = Path.Combine(TinyIoCContainer.Current.Resolve <AppHelper>().ApplicationPath, PlayerSettings.SettingsFileName);
                if (settings == null || !QuickIOFile.Exists(fileName))
                {
                    return(settings);
                }
                LogHost.Default.Info("loading player settings from {0}", fileName);
                var jsonString = QuickIOFile.ReadAllText(fileName);
                var fromThis   = JsonConvert.DeserializeObject <PlayerSettings>(jsonString);

                settings.MainWindow   = fromThis.MainWindow;
                settings.Medialib     = fromThis.Medialib;
                settings.PlayerEngine = fromThis.PlayerEngine;
            }
            catch (Exception exception)
            {
                LogHost.Default.ErrorException("could not load player settings", exception);
            }
            return(settings);
        }
Example #6
0
        public void UpdateFromTag(bool raisePropertyChanged = true)
        {
            var fileName = this.FullFileName;

            if (string.IsNullOrWhiteSpace(fileName) || !QuickIOFile.Exists(fileName))
            {
                return;
            }

            try
            {
                using (var file = TagLib.File.Create(fileName))
                {
                    // ALBUM -> iTunes=Album, WMP10=Album, Winamp=Album
                    this.Album = file.Tag.Album;
                    if (string.IsNullOrWhiteSpace(this.Album))
                    {
                        this.Album = UNKNOWN_STRING;
                    }
                    this.AlbumSort = file.Tag.AlbumSort;

                    // ALBUMARTIST
                    var albumArtists     = file.Tag.AlbumArtists.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    var albumArtistsSort = file.Tag.AlbumArtistsSort.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    this.FirstAlbumArtist     = albumArtists.Count > 1 ? string.Join("/", albumArtists) : file.Tag.FirstAlbumArtist;
                    this.FirstAlbumArtistSort = albumArtistsSort.Count > 1 ? string.Join("/", albumArtistsSort) : file.Tag.FirstAlbumArtistSort;

                    // ARTIST/Performer
                    var performers     = file.Tag.Performers.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    var performersSort = file.Tag.PerformersSort.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    this.FirstPerformer = performers.Count > 1 ? string.Join("/", performers) : file.Tag.FirstPerformer;
                    if (string.IsNullOrWhiteSpace(this.FirstPerformer))
                    {
                        this.FirstPerformer = UNKNOWN_STRING;
                    }
                    this.FirstPerformerSort = performersSort.Count > 1 ? string.Join("/", performersSort) : file.Tag.FirstPerformerSort;
                    if (string.IsNullOrWhiteSpace(this.FirstPerformerSort))
                    {
                        this.FirstPerformerSort = UNKNOWN_STRING;
                    }

                    // BPM
                    this.BPM = file.Tag.BeatsPerMinute;

                    // COMMENT
                    this.Comment = file.Tag.Comment;

                    // COMPOSER
                    var composers     = file.Tag.Composers.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    var composersSort = file.Tag.ComposersSort.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    this.FirstComposer     = composers.Count > 1 ? string.Join("/", composers) : file.Tag.FirstComposer;
                    this.FirstComposerSort = composersSort.Count > 1 ? string.Join("/", composersSort) : file.Tag.FirstComposerSort;

                    // CONDUCTOR
                    this.Conductor = file.Tag.Conductor;

                    // COPYRIGHT
                    this.Copyright = file.Tag.Copyright;

                    // TITLE
                    this.Title     = file.Tag.Title;
                    this.TitleSort = file.Tag.TitleSort;

                    // GENRE
                    var genres = file.Tag.Genres.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                    this.FirstGenre = genres.Count > 1 ? string.Join("/", genres) : file.Tag.FirstGenre;
                    if (string.IsNullOrWhiteSpace(this.FirstGenre))
                    {
                        this.FirstGenre = UNKNOWN_STRING;
                    }

                    this.Track      = file.Tag.Track;
                    this.TrackCount = file.Tag.TrackCount;
                    this.Disc       = file.Tag.Disc;
                    this.DiscCount  = file.Tag.DiscCount;
                    var trackFormat = this.TrackCount > 0 ? string.Format("Track {0}/{1}", this.Track, this.TrackCount) : string.Format("Track {0}", this.Track);
                    this.TrackInfo = this.DiscCount > 0 ? string.Format("{0}  Disc {1}/{2}", trackFormat, this.Disc, this.DiscCount) : trackFormat;
                    this.Year      = file.Tag.Year;
                    this.Grouping  = file.Tag.Grouping;

                    var isFirstPerformerEmpty = string.IsNullOrWhiteSpace(this.FirstPerformer) || Equals(this.FirstPerformer, UNKNOWN_STRING);
                    var isTitleEmpty          = string.IsNullOrWhiteSpace(this.Title) || Equals(this.FirstPerformer, UNKNOWN_STRING);
                    if (!isFirstPerformerEmpty && !isTitleEmpty)
                    {
                        this.FirstPerformerAndTitle = string.Concat(this.FirstPerformer, " - ", this.Title);
                    }
                    else if (!isFirstPerformerEmpty)
                    {
                        this.FirstPerformerAndTitle = this.FirstPerformer;
                    }
                    else if (!isTitleEmpty)
                    {
                        this.FirstPerformerAndTitle = this.Title;
                    }
                    else
                    {
                        this.FirstPerformerAndTitle = Path.GetFileNameWithoutExtension(this.FileName);
                    }

                    var isAlbumEmpty = string.IsNullOrWhiteSpace(this.Album) || Equals(this.Album, UNKNOWN_STRING);
                    if (!isFirstPerformerEmpty && !isAlbumEmpty)
                    {
                        this.FirstPerformerAndAlbum = string.Concat(this.FirstPerformer, " - ", this.Album);
                    }
                    else if (!isFirstPerformerEmpty)
                    {
                        this.FirstPerformerAndAlbum = this.FirstPerformer;
                    }
                    else if (!isAlbumEmpty)
                    {
                        this.FirstPerformerAndAlbum = this.Album;
                    }
                    else
                    {
                        this.FirstPerformerAndAlbum = Path.GetFileNameWithoutExtension(this.FileName);
                    }

                    if (file.Properties.MediaTypes != TagLib.MediaTypes.None)
                    {
                        this.Duration = file.Properties.Duration;
                        var codec = file.Properties.Codecs.FirstOrDefault(c => c is TagLib.Mpeg.AudioHeader);
                        this.IsVBR = codec != null && (((TagLib.Mpeg.AudioHeader)codec).VBRIHeader.Present || ((TagLib.Mpeg.AudioHeader)codec).XingHeader.Present);

                        this.AudioBitrate    = file.Properties.AudioBitrate;
                        this.AudioSampleRate = file.Properties.AudioSampleRate;
                    }
                }
            }
            catch (Exception e)
            {
                throw new MediaFileException("TagLib.File.Create failes!", e);
            }

            if (raisePropertyChanged)
            {
                this.RaisePropertyChanged();
            }
        }