Example #1
0
        /// <summary>
        /// Gets or sets the <see cref="MediaComponent"/> with the specified media type.
        /// Setting a new component on an existing media type component will throw.
        /// Getting a non existing media component fro the given media type will return null.
        /// </summary>
        /// <param name="mediaType">Type of the media.</param>
        /// <returns>The media component</returns>
        /// <exception cref="System.ArgumentException">When the media type is invalid</exception>
        /// <exception cref="System.ArgumentNullException">MediaComponent</exception>
        public MediaComponent this[MediaType mediaType]
        {
            get
            {
                lock (SyncLock) return(Items.ContainsKey(mediaType) ? Items[mediaType] : null);
            }
            set
            {
                lock (SyncLock)
                {
                    if (Items.ContainsKey(mediaType))
                    {
                        throw new ArgumentException($"A component for '{mediaType}' is already registered.");
                    }
                    Items[mediaType] = value ?? throw new ArgumentNullException($"{nameof(MediaComponent)} {nameof(value)} must not be null.");

                    if (HasVideo && HasAudio &&
                        (Video.StreamInfo.Disposition & ffmpeg.AV_DISPOSITION_ATTACHED_PIC) != ffmpeg.AV_DISPOSITION_ATTACHED_PIC)
                    {
                        Main = Video;
                        return;
                    }

                    Main = HasAudio ? Audio as MediaComponent : Video as MediaComponent;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets or sets the <see cref="MediaComponent"/> with the specified media type.
        /// Setting a new component on an existing media type component will throw.
        /// Getting a non existing media component fro the given media type will return null.
        /// </summary>
        /// <param name="mediaType">Type of the media.</param>
        /// <returns>The media component</returns>
        /// <exception cref="ArgumentException">When the media type is invalid</exception>
        /// <exception cref="ArgumentNullException">MediaComponent</exception>
        public MediaComponent this[MediaType mediaType]
        {
            get
            {
                lock (SyncLock) return(Items.ContainsKey(mediaType) ? Items[mediaType] : null);
            }
            set
            {
                lock (SyncLock)
                {
                    if (Items.ContainsKey(mediaType))
                    {
                        throw new ArgumentException($"A component for '{mediaType}' is already registered.");
                    }
                    Items[mediaType] = value ?? throw new ArgumentNullException($"{nameof(MediaComponent)} {nameof(value)} must not be null.");

                    // Try for the main component to be the video (if it's not stuff like audio album art, that is)
                    if (HasVideo && HasAudio &&
                        (Video.StreamInfo.Disposition & ffmpeg.AV_DISPOSITION_ATTACHED_PIC) != ffmpeg.AV_DISPOSITION_ATTACHED_PIC)
                    {
                        Main = Video;
                        return;
                    }

                    // If it was not vide, then it has to be audio (if it has audio)
                    if (HasAudio)
                    {
                        Main = Audio;
                        return;
                    }

                    // Set it to video even if it's attached pic stuff
                    if (HasVideo)
                    {
                        Main = Video;
                        return;
                    }

                    // As a last resort, set the main component to be the subtitles
                    if (HasSubtitles)
                    {
                        Main = Subtitles;
                        return;
                    }

                    // We whould never really hit this line
                    if (Items.Count > 0)
                    {
                        Main = Items.First().Value;
                    }
                }
            }
        }
 /// <summary>
 /// Gets or sets the <see cref="MediaComponent"/> with the specified media type.
 /// Setting a new component on an existing media type component will throw.
 /// Getting a non existing media component fro the given media type will return null.
 /// </summary>
 /// <param name="mediaType">Type of the media.</param>
 /// <returns>The media component</returns>
 /// <exception cref="ArgumentException">When the media type is invalid</exception>
 /// <exception cref="ArgumentNullException">MediaComponent</exception>
 public MediaComponent this[MediaType mediaType]
 {
     get
     {
         lock (SyncLock) return Items.ContainsKey(mediaType) ? Items[mediaType] : null;
     }
     set
     {
         lock (SyncLock)
         {
             if (Items.ContainsKey(mediaType))
                 throw new ArgumentException($"A component for '{mediaType}' is already registered.");
             Items[mediaType] = value ?? throw new ArgumentNullException($"{nameof(MediaComponent)} {nameof(value)} must not be null.");
             CachedComponents = null;
             ComputeMainComponent();
         }
     }
 }