Пример #1
0
        /// <summary>
        /// Gets the duration, in ticks, of the currently playing content
        /// </summary>
        public static long GetDurationOfCurrentlyPlayingMedia(MediaMetadata metadata)
        {
            if (metadata != null)
            {
                string duration = string.Empty;

                if (metadata.ContainsKey("Duration"))
                {
                    duration = metadata["Duration"] as string;
                }

                if (string.IsNullOrEmpty(duration) && metadata.ContainsKey("TrackDuration"))
                {
                    duration = metadata["TrackDuration"] as string;

                    // Found it in metadata, now parse
                    if (!string.IsNullOrEmpty(duration))
                    {
                        return(TimeSpan.FromSeconds(double.Parse(duration)).Ticks);
                    }
                }

                // Found it in metadata, now parse
                if (!string.IsNullOrEmpty(duration))
                {
                    return(TimeSpan.Parse(duration).Ticks);
                }
            }

            return(0);
        }
Пример #2
0
        /// <summary>
        /// Gets the title of the currently playing content
        /// </summary>
        public static string GetTitleOfCurrentlyPlayingMedia(MediaMetadata metadata)
        {
            if (metadata == null)
            {
                return(string.Empty);
            }

            string title = string.Empty;

            // Changed this to get the "Name" property instead.  That makes it compatable with DVD playback as well.
            if (metadata.ContainsKey("Name"))
            {
                title = metadata["Name"] as string;
            }

            if (string.IsNullOrEmpty(title) || title.ToLower().EndsWith(".wpl"))
            {
                if (metadata.ContainsKey("Title"))
                {
                    title = metadata["Title"] as string;
                }

                else if (metadata.ContainsKey("Uri"))
                {
                    // Use this for audio. Will get the path to the audio file even in the context of a playlist
                    // But with video this will return the wpl file
                    title = metadata["Uri"] as string;
                }
            }

            return(string.IsNullOrEmpty(title) ? string.Empty : title);
        }
        /// <summary>
        /// Gets the title of the currently playing content
        /// </summary>
        public static string GetTitleOfCurrentlyPlayingMedia(MediaMetadata metadata)
        {
            if (metadata == null) return string.Empty;

            string title = string.Empty;

            // Changed this to get the "Name" property instead.  That makes it compatable with DVD playback as well.
            if (metadata.ContainsKey("Name"))
            {
                title = metadata["Name"] as string;
            }

            if (string.IsNullOrEmpty(title) || title.ToLower().EndsWith(".wpl"))
            {
                if (metadata.ContainsKey("Title"))
                {
                    title = metadata["Title"] as string;
                }

                else if (metadata.ContainsKey("Uri"))
                {
                    // Use this for audio. Will get the path to the audio file even in the context of a playlist
                    // But with video this will return the wpl file
                    title = metadata["Uri"] as string;
                }
            }

            return string.IsNullOrEmpty(title) ? string.Empty : title;
        }
        /// <summary>
        /// Gets the duration, in ticks, of the currently playing content
        /// </summary>
        public static long GetDurationOfCurrentlyPlayingMedia(MediaMetadata metadata)
        {
            if (metadata != null)
            {
                string duration = string.Empty;

                if (metadata.ContainsKey("Duration"))
                {
                    duration = metadata["Duration"] as string;
                }

                if (string.IsNullOrEmpty(duration) && metadata.ContainsKey("TrackDuration"))
                {
                    duration = metadata["TrackDuration"] as string;

                    // Found it in metadata, now parse
                    if (!string.IsNullOrEmpty(duration))
                    {
                        return TimeSpan.FromSeconds(double.Parse(duration)).Ticks;
                    }
                }

                // Found it in metadata, now parse
                if (!string.IsNullOrEmpty(duration))
                {
                    return TimeSpan.Parse(duration).Ticks;
                }
            }

            return 0;
        }