Пример #1
0
        /// <summary>
        /// Retrieves the attribute names for a given playlist-based attribute source.
        /// </summary>
        /// <param name="Source">An AttributeSource specifying the type of media to inspect</param>
        /// <returns>void</returns>
        private void getMetadataFromPlaylist(AttributeSource Source)
        {
            IWMPPlaylist playlist = null;
            string name = "";

            try
            {
                switch (Source)
                {
                    // DVDs and CDs use the same CD object.
                    case AttributeSource.DVDToc:
                    case AttributeSource.CDPlaylist:
                        playlist = CD.Playlist;
                        break;
                    case AttributeSource.PlaylistCollection:
                        // Retrieve a playlist from the PlaylistCollection.
                        playlist = PLCollection.getAll().Item(0);
                        break;
                    case AttributeSource.CurrentPlaylist:
                        playlist = Player.currentPlaylist;
                        break;
                    default:
                        // This is strictly for debugging, it should never happen.
                        // If it does, we need a new case here or to fix the calling function.
                        throw new ArgumentOutOfRangeException("Source");
                }

                int cAttributes = playlist.attributeCount;

                // Log the attribute name and writability.
                for (int i = 0; i < cAttributes; i++)
                {
                    name = playlist.get_attributeName(i);
                    ListViewItem item = new ListViewItem(Source.ToString());

                    item.SubItems.Add(name);

                    item.SubItems.Add(playlist.getItemInfo(name));

                    // We'll assume it's read-only.
                    // If we can actually write it, we'll flip the bool.
                    // We do this because there is no IsReadOnlyItem property
                    // available on the playlist object.
                    bool bRO = true;

                    try
                    {
                        // Cache the value.
                        string temp = playlist.getItemInfo(name);
                        // Try to write something.
                        playlist.setItemInfo(name, "random");
                        // Write back the cached value.
                        playlist.setItemInfo(name, temp);
                        bRO = false;
                    }
                    catch (COMException)
                    {
                        // Writing the test value failed.
                        // bRO is true by default, so nothing to do here.
                    }

                    item.SubItems.Add(bRO.ToString());

                    listView1.Items.Add(item);
                }
            }
            catch (NullReferenceException)
            {
                ListViewItem item2 = new ListViewItem(Source.ToString());
                item2.SubItems.Add("NullReferenceException");
                item2.SubItems.Add("Does your library contain a playlist?");
                listView1.Items.Add(item2);
            }
            catch (ArgumentOutOfRangeException exc)
            {
                lblStatus.Text = "Invalid parameter in getMetadataFromPlaylist: " + exc.Message;
            }
            catch (COMException exc)
            {
                lblStatus.Text = "Exception in getMetadata: " + exc.Message;
            }
            catch
            {
                lblStatus.Text = "Exception in getMetadata.";
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieves the attribute names for a given playlist-based attribute source.
        /// </summary>
        /// <param name="Source">An AttributeSource specifying the type of media to inspect</param>
        /// <returns>void</returns>
        private void getMetadataFromPlaylist(AttributeSource Source)
        {
            IWMPPlaylist playlist = null;
            string       name     = "";

            try
            {
                switch (Source)
                {
                // DVDs and CDs use the same CD object.
                case AttributeSource.DVDToc:
                case AttributeSource.CDPlaylist:
                    playlist = CD.Playlist;
                    break;

                case AttributeSource.PlaylistCollection:
                    // Retrieve a playlist from the PlaylistCollection.
                    playlist = PLCollection.getAll().Item(0);
                    break;

                case AttributeSource.CurrentPlaylist:
                    playlist = Player.currentPlaylist;
                    break;

                default:
                    // This is strictly for debugging, it should never happen.
                    // If it does, we need a new case here or to fix the calling function.
                    throw new ArgumentOutOfRangeException("Source");
                }

                int cAttributes = playlist.attributeCount;

                // Log the attribute name and writability.
                for (int i = 0; i < cAttributes; i++)
                {
                    name = playlist.get_attributeName(i);
                    ListViewItem item = new ListViewItem(Source.ToString());

                    item.SubItems.Add(name);

                    item.SubItems.Add(playlist.getItemInfo(name));

                    // We'll assume it's read-only.
                    // If we can actually write it, we'll flip the bool.
                    // We do this because there is no IsReadOnlyItem property
                    // available on the playlist object.
                    bool bRO = true;

                    try
                    {
                        // Cache the value.
                        string temp = playlist.getItemInfo(name);
                        // Try to write something.
                        playlist.setItemInfo(name, "random");
                        // Write back the cached value.
                        playlist.setItemInfo(name, temp);
                        bRO = false;
                    }
                    catch (COMException)
                    {
                        // Writing the test value failed.
                        // bRO is true by default, so nothing to do here.
                    }

                    item.SubItems.Add(bRO.ToString());

                    listView1.Items.Add(item);
                }
            }
            catch (NullReferenceException)
            {
                ListViewItem item2 = new ListViewItem(Source.ToString());
                item2.SubItems.Add("NullReferenceException");
                item2.SubItems.Add("Does your library contain a playlist?");
                listView1.Items.Add(item2);
            }
            catch (ArgumentOutOfRangeException exc)
            {
                lblStatus.Text = "Invalid parameter in getMetadataFromPlaylist: " + exc.Message;
            }
            catch (COMException exc)
            {
                lblStatus.Text = "Exception in getMetadata: " + exc.Message;
            }
            catch
            {
                lblStatus.Text = "Exception in getMetadata.";
                throw;
            }
        }
Пример #3
0
        /// <summary>
        /// Displays the attribute information for a given media-based attribute source.
        /// </summary>
        /// <param name="Source">An AttributeSource specifying the schema to inspect.</param>
        /// <returns>void</returns>
        private void getMetadataFromMedia(AttributeSource Source)
        {
            IWMPPlaylist playlist = null;
            IWMPMedia media = null;

            string name = "";

            try
            {
                switch (Source)
                {
                    case AttributeSource.CDTrack:
                        playlist = CD.Playlist;
                        break;
                    case AttributeSource.CurrentMedia:
                        playlist = Player.currentPlaylist;
                        break;
                    default:
                        // Get a playlist filled with media for the specified schema.
                        playlist = MediaCollection.getByAttribute("MediaType", Source.ToString());
                        break;
                }

                if (0 != playlist.count)
                {
                    // Get the first item from the playlist.
                    media = playlist.get_Item(0);
                }
                else
                {
                    throw new EmptyPlaylistException();
                }

                int cAttributes = media.attributeCount;

                // Log the attribute name, value, and writability.
                for (int i = 0; i < cAttributes; i++)
                {
                    name = media.getAttributeName(i);

                    ListViewItem item = new ListViewItem(Source.ToString());

                    item.SubItems.Add(name);
                    item.SubItems.Add(media.getItemInfo(name));
                    bool bRO = media.isReadOnlyItem(name);
                    item.SubItems.Add(bRO.ToString());
                    listView1.Items.Add(item);
                }
            }
            catch (EmptyPlaylistException)
            {
                ListViewItem item3 = new ListViewItem(Source.ToString());
                item3.SubItems.Add("EmptyPlaylistException");
                item3.SubItems.Add("Does your library contain media for this type or source?");
                listView1.Items.Add(item3);
            }
            catch (COMException exc)
            {
                lblStatus.Text = "Exception in getMetadata: " + exc.Message;
            }
            catch
            {
                lblStatus.Text = "Exception in getMetadata.";
                throw;
            }

            // Insert an empty line in the listview.
            ListViewItem item2 = new ListViewItem("");
            listView1.Items.Add(item2);
        }
Пример #4
0
        /// <summary>
        /// Displays the attribute information for a given media-based attribute source.
        /// </summary>
        /// <param name="Source">An AttributeSource specifying the schema to inspect.</param>
        /// <returns>void</returns>
        private void getMetadataFromMedia(AttributeSource Source)
        {
            IWMPPlaylist playlist = null;
            IWMPMedia    media    = null;

            string name = "";

            try
            {
                switch (Source)
                {
                case AttributeSource.CDTrack:
                    playlist = CD.Playlist;
                    break;

                case AttributeSource.CurrentMedia:
                    playlist = Player.currentPlaylist;
                    break;

                default:
                    // Get a playlist filled with media for the specified schema.
                    playlist = MediaCollection.getByAttribute("MediaType", Source.ToString());
                    break;
                }

                if (0 != playlist.count)
                {
                    // Get the first item from the playlist.
                    media = playlist.get_Item(0);
                }
                else
                {
                    throw new EmptyPlaylistException();
                }

                int cAttributes = media.attributeCount;

                // Log the attribute name, value, and writability.
                for (int i = 0; i < cAttributes; i++)
                {
                    name = media.getAttributeName(i);

                    ListViewItem item = new ListViewItem(Source.ToString());

                    item.SubItems.Add(name);
                    item.SubItems.Add(media.getItemInfo(name));
                    bool bRO = media.isReadOnlyItem(name);
                    item.SubItems.Add(bRO.ToString());
                    listView1.Items.Add(item);
                }
            }
            catch (EmptyPlaylistException)
            {
                ListViewItem item3 = new ListViewItem(Source.ToString());
                item3.SubItems.Add("EmptyPlaylistException");
                item3.SubItems.Add("Does your library contain media for this type or source?");
                listView1.Items.Add(item3);
            }
            catch (COMException exc)
            {
                lblStatus.Text = "Exception in getMetadata: " + exc.Message;
            }
            catch
            {
                lblStatus.Text = "Exception in getMetadata.";
                throw;
            }

            // Insert an empty line in the listview.
            ListViewItem item2 = new ListViewItem("");

            listView1.Items.Add(item2);
        }