예제 #1
0
        /// <summary>
        /// Retrieves the current playback item using properties from MediaExperience and Transport
        /// </summary>
        private PlaybackStateEventArgs GetCurrentPlaybackState(string metadataTitle, long metadataDuration, long positionTicks)
        {
            int          filePlaylistPosition;
            int          currentMediaIndex;
            PlayableItem currentPlayableItem;

            if (CurrentMediaCollection == null)
            {
                currentPlayableItem = PlaybackControllerHelper.GetCurrentPlaybackItemUsingMetadataTitle(this, CurrentPlayableItems, metadataTitle, out filePlaylistPosition, out currentMediaIndex);
            }
            else
            {
                currentPlayableItem = PlaybackControllerHelper.GetCurrentPlaybackItemFromMediaCollection(CurrentPlayableItems, CurrentMediaCollection, out filePlaylistPosition, out currentMediaIndex);

                // When playing multiple files with MediaCollections, if you allow playback to finish, CurrentIndex will be reset to 0, but transport.Position will be equal to the duration of the last item played
                if (filePlaylistPosition == 0 && positionTicks >= metadataDuration)
                {
                    positionTicks = 0;
                }
            }

            return(new PlaybackStateEventArgs()
            {
                Position = positionTicks,
                CurrentFileIndex = filePlaylistPosition,
                DurationFromPlayer = metadataDuration,
                Item = currentPlayableItem,
                CurrentMediaIndex = currentMediaIndex
            });
        }