Ejemplo n.º 1
0
        // AJAX: /Player/GetPlaylist
        public ActionResult GetPlaylist()
        {
            try
            {
                var tracks = new List<TrackModel>();

                for (var i = 0; i < Player.currentPlaylist.count; i++)
                {
                    var item = Player.currentPlaylist.get_Item(i);

                    short trackNumber = 1;
                    short.TryParse(item.getItemInfo("WM/TrackNumber"), out trackNumber);

                    short year = 2000;
                    short.TryParse(item.getItemInfo("WM/Year"), out year);

                    var track = new TrackModel()
                    {
                        Id = Guid.Empty,
                        Name = item.name,
                        Path = item.sourceURL,
                        Artist = item.getItemInfo("Author"),
                        Album = item.getItemInfo("WM/AlbumTitle"),
                        Number = trackNumber,
                        DurationString = item.durationString,
                        Year = year
                    };
                    tracks.Add(track);
                }

                return Json(new
                {
                    aaTracks = GetTrackJson(tracks)
                }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(500, string.Format("{0}: {1}", ex.Message, ex.InnerException));
            }
        }
Ejemplo n.º 2
0
        private void AddTrack(FileInfo file)
        {
            try
            {
                var ultraId3 = new UltraID3();
                ultraId3.Read(file.FullName);

                var track = new TrackModel()
                                {
                                    Id = Guid.NewGuid(),
                                    Name = ultraId3.Title,
                                    Genre = ultraId3.Genre,
                                    Duration = ultraId3.Duration.TotalSeconds,
                                    Number = ultraId3.TrackNum,
                                    Path = file.FullName,
                                    Year = ultraId3.Year
                                };

                var album = GetAlbum(ultraId3.Artist, ultraId3.Album);

                var id3PictureFrames = ultraId3.ID3v2Tag.Frames.GetFrames(MultipleInstanceID3v2FrameTypes.ID3v23Picture);
                if (id3PictureFrames != null && id3PictureFrames.Count > 0)
                {
                    track.Image = string.Format(@"{0}\\Images\\{1}.png", Path, album.Id);

                    if (!System.IO.File.Exists(track.Image))
                        (((ID3v23PictureFrame) id3PictureFrames[0]).Picture).Save(track.Image,
                                                                              System.Drawing.Imaging.ImageFormat.Png);
                }

                album.Year = ultraId3.Year;
                album.Genre = ultraId3.Genre;
                album.Image = track.Image;
                album.Tracks.Add(track);
            }
            catch (Exception ex)
            {
                // Log : File failed to be added
                //throw new Exception(string.Format("File failed to be added {0}", file.FullName), ex);
            }
        }