Inheritance: Windows.UI.Xaml.DependencyObject, ITimelineMarker
        public static void ConvertSrtToTimlineMarker(string srt, MediaPlayer me)
        {

            TimelineMarker timelineMarker = new TimelineMarker();
            var pattern = new string[1] {"\r\n\r\n"};
            var shortPattern = new string[1] { "\r\n" };
            var timeSplitter = new string[1] { " --> " };
            var srtSplit = srt.Split(pattern, StringSplitOptions.None);

            foreach (string s in srtSplit)
            {
                try
                {
                    var lines = s.Split(shortPattern, StringSplitOptions.None);
                    var timeStrings = lines[1].Split(timeSplitter, StringSplitOptions.None);
                    var start = timeStrings[0];
                    var end = timeStrings[1];
                    var text = String.Join(Environment.NewLine, lines.Skip(2));

                    TimelineMarker tlm = new TimelineMarker();
                    tlm.Time = TimeSpan.Parse(start.Replace(',', '.'));
                    tlm.Text = text;
                    me.Markers.Add(tlm);
                    TimelineMarker tlEnd = new TimelineMarker();
                    tlEnd.Time = TimeSpan.Parse(end.Replace(',', '.'));
                    tlEnd.Text = "";
                    me.Markers.Add(tlEnd);
                }
                catch { }
            }
        }
        void theSound_MediaOpened(object sender, RoutedEventArgs e)
        {
            if (LoopTime > 0)
            {
                // set up our loop marker (this avoids gaps in loop)
                MediaElement sound = (sender as MediaElement);

                TimelineMarker marker = new TimelineMarker();
                marker.Text = "x";
                marker.Type = "y";
                marker.Time = TimeSpan.FromMilliseconds(LoopTime);

                sound.Markers.Add(marker);
            }
        }
示例#3
0
        private async void Collection_Click_1(object sender, RoutedEventArgs e)
        {
            if (EnsureUnsnapped())
            {
                FileOpenPicker pkr = new FileOpenPicker();
                pkr.ViewMode = PickerViewMode.List;
                pkr.SuggestedStartLocation = PickerLocationId.MusicLibrary;
                pkr.FileTypeFilter.Add(".mp3");

                StorageFile file = await pkr.PickSingleFileAsync();
                if (null != file)
                {
                    
                    var strm = await file.OpenAsync(FileAccessMode.Read);
                    Playlist.NowPlaying.Clear();
                    App.GlobalAudioElement.AudioCategory = Windows.UI.Xaml.Media.AudioCategory.BackgroundCapableMedia;
                    //mediaPlayer.SetSource(strm, file.ContentType);
                    App.GlobalAudioElement.SetSource(strm, file.ContentType);
                    App.GlobalAudioElement.Play();
                    //timelineSlider.Maximum = App.GlobalAudioElement.NaturalDuration.TimeSpan.TotalMilliseconds;
                    isScrobbledOnce = false;
                    
                    MediaControl.IsPlaying = true;
                    //PlayPauseBtn.Content = "";

                    id3 = await file.Properties.GetMusicPropertiesAsync();
                    SongTitle.Text = id3.Title;
                    Artist.Text = id3.Artist;                    

                    Playlist.NowPlaying.Add(id3);
                    Lastfm.track_updateNowPlaying(id3);

                    string xmlinfo = await Lastfm.track_getInfo(id3);
                    string artistinfo = await Lastfm.artist_getInfo(id3.Artist);
                    try
                    {
                        using (XmlReader rd = XmlReader.Create(new StringReader(xmlinfo)))
                        {
                            rd.ReadToFollowing("name");
                            TitleInfoTbx.Text = rd.ReadElementContentAsString();
                            rd.ReadToFollowing("artist");
                            rd.ReadToDescendant("name");
                            SubtitleInfoTbx.Text = rd.ReadElementContentAsString();                            
                        }
                        
                        using(XmlReader rd=XmlReader.Create(new StringReader(xmlinfo)))
                        {
                            rd.ReadToFollowing("image");
                            rd.ReadToNextSibling("image");
                            rd.ReadToNextSibling("image");
                            Uri src = new Uri(rd.ReadElementContentAsString(), UriKind.Absolute);
                            AlbumArtHolder.Source = new BitmapImage(src);                            
                        }
                        using (XmlReader rd = XmlReader.Create(new StringReader(xmlinfo)))
                        {
                            rd.ReadToFollowing("wiki");
                            rd.ReadToDescendant("summary");
                            SummaryInfoTbx.Text = rd.ReadElementContentAsString();
                        }
                    }
                    catch (Exception) 
                    {
                        try
                        {
                            using (XmlReader rd = XmlReader.Create(new StringReader(artistinfo)))
                            {
                                rd.ReadToFollowing("image");
                                rd.ReadToNextSibling("image");
                                rd.ReadToNextSibling("image");
                                Uri src = new Uri(rd.ReadElementContentAsString(), UriKind.Absolute);
                                AlbumArtHolder.Source = new BitmapImage(src);                        
                            }
                        }
                        catch (Exception) { AlbumArtHolder.Source = null; }
                    }
                    //prepare for scrobble
                    TimelineMarker tlm = new TimelineMarker();
                    tlm.Time = new System.TimeSpan(0,0,(int)id3.Duration.TotalSeconds/2);
                    App.GlobalAudioElement.Markers.Clear();
                    App.GlobalAudioElement.Markers.Add(tlm);
                    if (id3.Duration > new System.TimeSpan(0, 0, 30))
                    {
                        await Lastfm.track_scrobble(id3);
                        isScrobbledOnce = true;

                        //App.GlobalAudioElement.MarkerReached += mediaPlayer_MarkerReached_scrobble; //scrobble
                    }
                }
                else
                { return; }
            }
        }
示例#4
0
 /// <summary>
 /// Click handler for the "Add marker" button.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddMarkerButton_Click(object sender, RoutedEventArgs e)
 {
     // Add a marker to the MediaElement at 2 seconds past the current time
     TimelineMarker marker = new TimelineMarker();
     marker.Text = "Marker Fired";
     marker.Time = TimeSpan.FromSeconds(Scenario3MediaElement.Position.TotalSeconds + 2);
     Scenario3MediaElement.Markers.Add(marker);
     
     Scenario3Text.Text += String.Format("Marker added at time = {0:g}\n", Math.Round(Scenario3MediaElement.Position.TotalSeconds + 2, 2));
 }
 internal MarkerReachedEventArgs(TimelineMarker marker)
 {
     Marker = marker;
 }
        void Image_ImageOpened(object sender, RoutedEventArgs e)
        {
            State = AdState.Loaded;
            if (AdLoaded != null) AdLoaded(this, EventArgs.Empty);

            if (SkippableOffset != null)
            {
                // create a marker for the skippable offset
                TimelineMarker skippableOffsetMarker = null;
                if (!SkippableOffset.IsAbsolute)
                {
                    skippableOffsetMarker = new TimelineMarker() { Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * SkippableOffset.RelativeOffset) };
                }
                else
                {
                    skippableOffsetMarker = new TimelineMarker() { Time = SkippableOffset.AbsoluteOffset };
                }
                if (skippableOffsetMarker != null)
                {
                    skippableOffsetMarker.Type = Marker_SkippableOffset;
                    markerHelper.Markers.Add(skippableOffsetMarker);
                }
            }

            if (SuggestedDuration.HasValue)
            {
                // create markers for the quartile events
                markerHelper.Markers.Add(new TimelineMarker() { Type = Marker_FirstQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .25) });
                markerHelper.Markers.Add(new TimelineMarker() { Type = Marker_Midpoint, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .5) });
                markerHelper.Markers.Add(new TimelineMarker() { Type = Marker_ThirdQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .75) });
                // create marker for duration
                markerHelper.Markers.Add(new TimelineMarker() { Type = Marker_DurationReached, Time = AdDuration });
            }

            markerHelper.MarkerReached += markerHelper_MarkerReached;
        }
 private void OnMarkerReached(TimelineMarker marker)
 {
     switch (marker.Type)
     {
         case Marker_SkippableOffset:
             AdSkippableState = true;
             mediaElement.Markers.Remove(marker);
             break;
         case Marker_FirstQuartile:
             if (AdVideoFirstQuartile != null) AdVideoFirstQuartile(this, EventArgs.Empty);
             mediaElement.Markers.Remove(marker);
             break;
         case Marker_Midpoint:
             if (AdVideoMidpoint != null) AdVideoMidpoint(this, EventArgs.Empty);
             mediaElement.Markers.Remove(marker);
             break;
         case Marker_ThirdQuartile:
             if (AdVideoThirdQuartile != null) AdVideoThirdQuartile(this, EventArgs.Empty);
             mediaElement.Markers.Remove(marker);
             break;
         case Marker_DurationReached:
             if (!adCompleted)
             {
                 adCompleted = true;
                 if (AdVideoComplete != null) AdVideoComplete(this, EventArgs.Empty);
             }
             mediaElement.Markers.Remove(marker);
             StopAd();
             break;
         default:
             mediaElement.Markers.Remove(marker);
             break;
     }
 }
        void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
        {
            OnLoaded();

            if (SkippableOffset != null)
            {
                // create a marker for the skippable offset
                TimelineMarker skippableOffsetMarker = null;
                if (!SkippableOffset.IsAbsolute)
                {
                    skippableOffsetMarker = new TimelineMarker() { Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * SkippableOffset.RelativeOffset) };
                }
                else
                {
                    skippableOffsetMarker = new TimelineMarker() { Time = SkippableOffset.AbsoluteOffset };
                }
                if (skippableOffsetMarker != null)
                {
                    skippableOffsetMarker.Type = Marker_SkippableOffset;
                    mediaElement.Markers.Add(skippableOffsetMarker);
                }
            }

            adCompleted = false;
            // create markers for the quartile events
            mediaElement.Markers.Add(new TimelineMarker() { Type = Marker_FirstQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .25) });
            mediaElement.Markers.Add(new TimelineMarker() { Type = Marker_Midpoint, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .5) });
            mediaElement.Markers.Add(new TimelineMarker() { Type = Marker_ThirdQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .75) });

            if (MaxDuration.HasValue)
            {
                // create marker for max duration
                mediaElement.Markers.Add(new TimelineMarker() { Type = Marker_DurationReached, Time = MaxDuration.Value });
            }

#if !HACK_MARKERREACHED
            mediaElement.MarkerReached += MediaElement_MarkerReached;
#endif
        }