コード例 #1
0
ファイル: gui_editTag.cs プロジェクト: philwo/crossfade
 public void readMedium(Media tmp)
 {
     try
     {
         media = tmp;
         pictureBox1.Image = null;
         textBox1.Text = media.TrackNr.ToString();
         textBox2.Text = media.Title;
         textBox3.Text = media.Album;
         textBox4.Text = media.Artist;
         textBox5.Text = media.Year.ToString();
         textBox6.Text = media.Genre;
         textBox7.Text = media.Comment;
         textBox8.Text = media.Composer;
         textBox9.Text = media.Copyright;
         if (media.Cover != null)
             pictureBox1.Image = Image.FromStream(media.Cover);
     }
     catch (IOException ex)
     {
         throw ex;
     }
 }
コード例 #2
0
ファイル: play_video.cs プロジェクト: philwo/crossfade
 // Bekannter Bug bei DirectX: Laden eines Videos verursacht LoaderLock Exception.
 // Bitte unter Debug-->Exceptions-->ManagedDebuggingAsssistants den Haken bei "LoaderLock" entfernen.
 /**
  * Opens a media file and optionally updates some information in the media object, which was discovered after opening the file
  * \param media The media object which should get opened
  * */
 public void open(ref Media media)
 {
     setFilePathFromUri(media.uri);
     if (filepath != null)
     {
         try
         {
             PictureBox picbox;
             DXvideo = new Video(filepath, false);
             media.Length = (int)getLength();
             picbox = Program.gui.getVideoCanvas();
             DXvideo.Owner = picbox;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #3
0
ファイル: Playlist.cs プロジェクト: philwo/crossfade
        /**
        *  Adds an Array of Medias to the current playlist
         * \param media An array with one or more MediaObjects
        */
        public void addMedia(Media[] media)
        {
            if (media == null) return;

            foreach (Media m in media)
                addMedia(m);
        }
コード例 #4
0
ファイル: Playlist.cs プロジェクト: philwo/crossfade
        /**
        *  Add a Media to the current playlist.
         * \param media A Mediaobject that sould be added.
        */
        public void addMedia(Media media)
        {
            if (media == null) return;

            mediaList.Add(FileInfo.Instance.getInfo(media));
        }
コード例 #5
0
ファイル: Media.cs プロジェクト: philwo/crossfade
        /**
         * Adds a new media object to the database
         *
         * \param media The media object which is to be added to the database
         * */
        private void addFile(Media media)
        {
            MDBAction add;
            Media mInDB = null;

            if (media.uri.Scheme == Uri.UriSchemeFile)
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(media.uri.LocalPath);

                foreach (Media m in mediaList)
                {
                    if (m.uri == media.uri)
                    {
                        // File already in mediaDB
                        System.Diagnostics.Debug.Print("Already in MDB: " + media.uri);
                        mInDB = m;
                        break;
                    }
                    //else if (m.SHA1Sum == media.SHA1Sum)
                    //{
                    //    // Duplicate file
                    //    System.Diagnostics.Debug.Print("Duplicate file: " + media.uri + " vs. " + m.uri);
                    //}
                }

                if (mInDB == null)
                {
                    // If it's not in the database, then it should get added
                    add = MDBAction.Add;
                }
                else
                {
                    // Check the date of last modification
                    if (fi.LastWriteTime != mInDB.MTime)
                    {
                        // It's been modified since our last indexing, replace the old version
                        add = MDBAction.Replace;
                    }
                    else
                    {
                        // It's the same file, we can keep the information we already have in the database
                        add = MDBAction.Skip;
                    }
                }
            }
            else
            {
                /* not-file:/-URIs don't have a modification date, so we add it, if it's not in the database, and keep the version in the database, if the same URI already
                 * exists in the MediaDB */
                foreach (Media m in mediaList)
                {
                    if (m.uri == media.uri)
                    {
                        add = MDBAction.Skip;
                        break;
                    }
                }

                add = MDBAction.Add;
            }

            switch (add)
            {
                case MDBAction.Add:
                    System.Diagnostics.Debug.Print("Adding media: " + media.uri);
                    mediaList.Add(FileInfo.Instance.getInfo(media));
                    break;
                case MDBAction.Replace:
                    System.Diagnostics.Debug.Print("Replacing media: " + media.uri);
                    mediaList.Remove(mInDB);
                    mediaList.Add(FileInfo.Instance.getInfo(media));
                    break;
                case MDBAction.Skip:
                    System.Diagnostics.Debug.Print("Skipping media: " + media.uri);
                    break;
            }
            gui_SplashScreen.SetProgressBar(1);
        }
コード例 #6
0
ファイル: play_pic.cs プロジェクト: philwo/crossfade
 /**
  * Opens a media file and optionally updates some information in the media object, which was discovered after opening the file
  * \param media The media object which should get opened
  * */
 public void open(ref Media media)
 {
     media.Length = Crossfade.Properties.Settings.Default.PictureShowTime;
     setFilePathFromUri(media.uri);
 }
コード例 #7
0
ファイル: Player.cs プロジェクト: philwo/crossfade
        /**
        *  Opens a Media File
         * \param
        */
        public void open(ref Media file)
        {
            if (file == null) return;

            IPlayer oldPlayer = _player;

            if (file.uri.Scheme == Uri.UriSchemeFile)
            {
                switch (file.Type)
                {
                    case Media.MediaType.Audio:
                        _player = _playerFMOD;
                        Program.gui.setViewmode(Viewmode.Playlist);
                        break;
                    case Media.MediaType.Picture:
                        _player = _playerPic;
                        Program.gui.setViewmode(Viewmode.Picture);
                        break;
                    case Media.MediaType.Video:
                        _player = _playerVideo;
                        Program.gui.setViewmode(Viewmode.Video);
                        break;
                    case Media.MediaType.Unknown:
                        _player = null;
                        break;
                }
            }
            else
            {
                _player = _playerFMOD;
            }

            if (oldPlayer != _player && oldPlayer != null)
                oldPlayer.stop();

            try
            {
            if (_player != null)
                try
                {
                    _player.open(ref file);
                }
                catch (InvalidOperationException ie)
                {
                    throw ie;
                }
            }
            catch (System.Net.WebException w)
            {
                throw w;
            }
        }
コード例 #8
0
ファイル: gui_krypton.cs プロジェクト: philwo/crossfade
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.CheckFileExists = true;
            ofd.CheckPathExists = true;
            ofd.DereferenceLinks = true;
            ofd.RestoreDirectory = true;
            ofd.Filter = "Musikdateien (*.mp3, *.ogg, *.flac, *.wma)|*.mp3;*.ogg;*.flac; *.wma|Alle Dateien (*.*)|*.*";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Media media = new Media(new Uri(System.IO.Path.GetFullPath(ofd.FileName)));
                if (mediaListBackup != null)
                {
                    mediaListBackup.Add(FileInfo.Instance.getInfo(media));
                }
                else
                {
                    Playlist.Instance.addMedia(media);
                }
                this.updatePlaylist();
            }
        }
コード例 #9
0
ファイル: gui_krypton.cs プロジェクト: philwo/crossfade
        private void addMediaToPlaylist(String s)
        {
            string ext = Path.GetExtension(s);

            if (ext.ToLower().EndsWith(".m3u"))
            {
                Media[] arr = Playlist.Instance.parseM3U(new Uri(s));

                if (mediaListBackup != null)
                {
                    foreach (Media m in arr)
                    {
                        mediaListBackup.Add(FileInfo.Instance.getInfo(m));
                    }
                }
                else
                {
                    foreach (Media m in arr)
                    {
                        Playlist.Instance.addMedia(FileInfo.Instance.getInfo(m));
                    }
                }
            }
            else
            {
                Media media = new Media(new Uri(s));

                if (mediaListBackup != null)
                {
                    mediaListBackup.Add(FileInfo.Instance.getInfo(media));
                }
                else
                {
                    Playlist.Instance.addMedia(media);
                }
            }

            this.updatePlaylist();
        }
コード例 #10
0
ファイル: FileInfo.cs プロジェクト: philwo/crossfade
        /**
         * Main function which gets passed a media object and tries to complete the missing information about this object. It calls TagLib to read ID3v2 tags, fiHash
         * to calculate the SHA1-hashvalue, etc.
         *
         * \param media The media object which should get completed.
         * \return The media object with hopefully more information that before.
         * */
        public Media getInfo(Media media)
        {
            if (media.uri.Scheme == Uri.UriSchemeFile)
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(media.uri.LocalPath);

                if (media.MTime != fi.LastWriteTime)
                {
                    System.Diagnostics.Debug.Print("MTime modified, re-reading FileInfo: " + media.uri);

                    /* Filehash */
                    try
                    {
                        if (media.Type != Media.MediaType.Video)
                        {
                            fiHash hash = new fiHash(media.uri);
                            media.SHA1Sum = hash.SHA256;
                        }

                        if (media.uri.LocalPath.ToLower().EndsWith(".cda"))
                        {
                            media.Album = "Unknown Audio CD";
                            media.Artist = "Unknown";
                            media.Title = media.uri.LocalPath.ToString();

                            /* fixme, get length of audio track here */
                            //media.Length = ;

                            string trackname = Path.GetFileNameWithoutExtension(media.uri.LocalPath);
                            string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.";
                            string tracknr = trackname.Trim(alphabet.ToCharArray());

                            try
                            {
                                media.TrackNr = Convert.ToUInt32(tracknr);
                            }
                            catch (InvalidCastException)
                            {
                                media.TrackNr = 1;
                            }
                        }
                        else if (media.Type == Media.MediaType.Audio)
                        {
                            /* Taglib */
                            LibraryTagLib tl = new LibraryTagLib(media.uri);
                            media.TrackNr = tl.Tracknr;
                            media.Title = tl.Title;
                            media.Album = tl.Album;
                            media.Artist = tl.Artist;
                            media.Year = tl.Year;
                            media.Genre = tl.Genre;
                            media.Comment = tl.Comment;
                            media.Composer = tl.Composer;
                            media.Copyright = tl.Copyright;
                            media.Length = tl.Length;
                            media.Rating = tl.Rating;
                            if (media.Album == "" && media.Title == "" && media.Artist == "")
                            {
                                string media_file = media.uri.LocalPath;
                                media.Title = media_file.Substring(media_file.LastIndexOf("\\") + 1);
                            }
                        }
                        else if (media.Type == Media.MediaType.Picture)
                        {
                            string media_file = media.uri.LocalPath;
                            media.Title = media_file.Substring(media_file.LastIndexOf("\\") + 1);
                            media.Artist = "(Image)";
                            media.Length = 10000;
                        }
                        else if (media.Type == Media.MediaType.Video)
                        {
                            string media_file = media.uri.LocalPath;
                            media.Title = media_file.Substring(media_file.LastIndexOf("\\") + 1);
                            media.Artist = "(Video)";
                        }
                        else
                        {
                            media.Title = "(Unknown)";
                            media.Artist = "(Unknown)";
                            media.Album = "(Unknown)";
                        }

                        /* LastWriteTime */
                        media.MTime = fi.LastWriteTime;
                    }
                    catch (IOException ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    System.Diagnostics.Debug.Print("MTime not modified, skipping FileInfo: " + media.uri);
                }
            }

            return media;
        }
コード例 #11
0
ファイル: queryEngine.cs プロジェクト: philwo/crossfade
        private static bool checkMediaForMatch(Media m, Query.Match match)
        {
            bool valid = false;
            List<string> lhs = new List<string>(3);

            switch (match.lhs)
            {
                case Query.MatchLHS.All:
                    lhs.Add(m.Artist);
                    lhs.Add(m.Album);
                    lhs.Add(m.Title);
                    lhs.Add(m.uri.ToString());
                    break;
                case Query.MatchLHS.SHA1:
                    lhs.Add(m.SHA1Sum);
                    break;
                case Query.MatchLHS.TrackNr:
                    lhs.Add(m.TrackNr.ToString());
                    break;
                case Query.MatchLHS.Title:
                    lhs.Add(m.Title);
                    break;
                case Query.MatchLHS.Album:
                    lhs.Add(m.Album);
                    break;
                case Query.MatchLHS.Artist:
                    lhs.Add(m.Artist);
                    break;
                case Query.MatchLHS.Rating:
                    lhs.Add(m.Rating.ToString());
                    break;
                case Query.MatchLHS.Year:
                    lhs.Add(m.Year.ToString());
                    break;
                case Query.MatchLHS.Genre:
                    lhs.Add(m.Genre);
                    break;
                case Query.MatchLHS.Comment:
                    lhs.Add(m.Comment);
                    break;
                default:
                    throw new ArgumentException("Invalid matchLHS!");
            }

            foreach (string target in lhs)
            {
                try
                {
                    switch (match.op)
                    {
                        case Query.MatchOp.Contains:
                            valid = valid || target.ToUpper().Contains(match.rhs.ToUpper());
                            break;
                        case Query.MatchOp.Is:
                            valid = valid || (String.Compare(target, match.rhs, true) == 0);
                            break;
                        case Query.MatchOp.IsNot:
                            valid = valid || (String.Compare(target, match.rhs, true) != 0);
                            break;
                    }
                }
                catch (NullReferenceException)
                {
                    System.Diagnostics.Debug.Print("NullReferenceException in queryEngine, not matching target");
                }
            }

            return valid;
        }
コード例 #12
0
ファイル: queryEngine.cs プロジェクト: philwo/crossfade
        /**
        *  FIXME
        */
        public Media[] query(Query q)
        {
            List<Media> resultSet = new List<Media>();

            foreach (Media m in _mediaList)
            {
                bool matches;

                switch (q.conj)
                {
                    case Query.Conjunction.And:
                        matches = true;
                        break;
                    case Query.Conjunction.Or:
                        matches = false;
                        break;
                    default:
                        throw new ArgumentException("Invalid Query.Conjunction!");
                }

                foreach (Query.Match match in q.match)
                {
                    bool valid = checkMediaForMatch(m, match);

                    if (q.conj == Query.Conjunction.And)
                    {
                        if (!valid)
                        {
                            matches = false;
                            break;
                        }
                        else
                        {
                        }
                    }
                    else if (q.conj == Query.Conjunction.Or)
                    {
                        if (!valid)
                        {
                        }
                        else
                        {
                            matches = true;
                            break;
                        }
                    }
                }

                if (matches)
                    resultSet.Add(m);
            }

            // Sort
            switch (q.sort.by)
            {
                case Query.SortBy.Album:
                    resultSet.Sort(new ObjectComparer<Media>("Album"));
                    break;
                case Query.SortBy.Artist:
                    resultSet.Sort(new ObjectComparer<Media>("Artist"));
                    break;
                case Query.SortBy.Smart:
                    resultSet.Sort(new ObjectComparer<Media>("Artist ASC, Album ASC, TrackNr ASC", true));
                    break;
                case Query.SortBy.Title:
                    resultSet.Sort(new ObjectComparer<Media>("Title"));
                    break;
                case Query.SortBy.TrackNr:
                    resultSet.Sort(new ObjectComparer<Media>("TrackNr"));
                    break;
                case Query.SortBy.Year:
                    resultSet.Sort(new ObjectComparer<Media>("Year"));
                    break;
            }

            // Limit to numberOfResults
            if (q.numberOfResults > -1)
            {
                int numResults = Math.Min(q.numberOfResults, resultSet.Count);

                Media[] output = new Media[numResults];
                resultSet.CopyTo(0, output, 0, numResults);
                return output;
            }
            else
            {
                return resultSet.ToArray();
            }
        }