private static void OnMediaItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MediaItemPlayer mip = d as MediaItemPlayer;

            if (!mip.removingMediaItem)
            {
                Int32 oldValue = mip.SelectedIndex;
                Int32 newValue = -1;

                if (mip.MediaItems.Count > 0)
                {
                    newValue = 0;
                }

                if (oldValue == newValue)
                {
                    OnSelectedIndexPropertyChanged(d, new DependencyPropertyChangedEventArgs(SelectedIndexProperty, oldValue, newValue));
                }
                else
                {
                    mip.SelectedIndex = newValue;
                }
            }

            if (mip.MediaItems != null)
            {
                mip.MediaItems.CollectionChanged -= mip.MediaItems_CollectionChanged;
                mip.MediaItems.CollectionChanged += mip.MediaItems_CollectionChanged;
            }
        }
        private static void OnPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MediaItemPlayer mip = d as MediaItemPlayer;

            if (mip.positionUpdatesPart)
            {
                if (mip.meNowPlaying != null)
                {
                    mip.SetPart();
                }
            }
        }
        private static void OnSelectedMediaItemPartIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MediaItemPlayer mip = d as MediaItemPlayer;

            if (mip.SelectedMediaItem != null)
            {
                MediaItemPart selectedMediaItemPart = mip.SelectedMediaItem.Parts[mip.SelectedMediaItemPartIndex];
                mip.SelectedMediaItemPart = selectedMediaItemPart;
            }
            else
            {
                mip.SelectedMediaItemPart = null;
            }
        }
        private static void OnSelectedIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MediaItemPlayer mip = d as MediaItemPlayer;

            if (!mip.removingMediaItem)
            {
                mip.CanSkipPrevious = false;
                mip.CanSkipNext     = false;

                if (mip.SelectedIndex == -1)
                {
                    mip.SelectedMediaItem = null;
                    mip.Position          = TimeSpan.FromSeconds(0);

                    return;
                }
                else
                {
                    MediaItem selectedMediaItem = mip.MediaItems[mip.SelectedIndex];

                    CancelMediaItemsOperationEventArgs cmioea = new CancelMediaItemsOperationEventArgs(new MediaItem[1] {
                        selectedMediaItem
                    });
                    mip.OnOpeningMediaItem(cmioea);

                    if (cmioea.Cancel)
                    {
                        mip.SkipNext();
                        return;
                    }

                    mip.SelectedMediaItem = selectedMediaItem;
                }
            }

            mip.SetCanSkip();
        }
        private static void OnPlayStatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MediaItemPlayer mip = d as MediaItemPlayer;

            mip.OnPlayStateChanged();
        }
        private static void OnSelectedMediaItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MediaItemPlayer npv = d as MediaItemPlayer;

            npv.SelectedMediaItemPartIndex = 0;
        }