/// <summary> /// Called when a new track requires audio decoding /// (typically because it is about to start playing) /// </summary> /// <param name="track"> /// The track that needs audio streaming /// </param> /// <param name="streamer"> /// The AudioStreamer object to which a MediaStreamSource should be /// attached to commence playback /// </param> /// <remarks> /// To invoke this method for a track set the Source parameter of the AudioTrack to null /// before setting into the Track property of the BackgroundAudioPlayer instance /// property set to true; /// otherwise it is assumed that the system will perform all streaming /// and decoding /// </remarks> protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer) { //TODO: Set the SetSource property of streamer to a MSS source var data = track.Tag.ToString().Split('$'); var url = data[data.Length - 1]; var type = data[2]; #if DEBUG System.Diagnostics.Debug.WriteLine("AudioStreamer:OnBeginStreaming - Type: " + type); #endif switch (type.ToLower()) { case "shoutcast": { mms = new Silverlight.Media.ShoutcastMediaStreamSource(new Uri(url), true); //track.Title = "Moo"; mms.MetadataChanged += mms_MetadataChanged; mms.Connected += mms_Connected; mms.Closed += mms_Closed; streamer.SetSource(mms); } break; } }
protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer) { System.Diagnostics.Debug.WriteLine("OnBeginStreaming"); MidiStreamSource mss = new MidiStreamSource(); // Event handler for when a track is complete or the user switches tracks mss.StreamComplete += new EventHandler(mss_StreamComplete); // Set the source streamer.SetSource(mss); }
/// <summary> /// Called when a new track requires audio decoding /// (typically because it is about to start playing) /// </summary> /// <param name="track"> /// The track that needs audio streaming /// </param> /// <param name="streamer"> /// The AudioStreamer object to which a MediaStreamSource should be /// attached to commence playback /// </param> /// <remarks> /// To invoke this method for a track set the Source parameter of the AudioTrack to null /// before setting into the Track property of the BackgroundAudioPlayer instance /// property set to true; /// otherwise it is assumed that the system will perform all streaming /// and decoding /// </remarks> protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer) { lock (AudioTrackStreamer.syncRoot) { AudioTrackStreamer.mss = new ShoutcastMediaStreamSource(new Uri(track.Tag)); AudioTrackStreamer.mss.MetadataChanged += new RoutedEventHandler(AudioTrackStreamer.MetadataChanged); AudioTrackStreamer.mss.Closed += (s, e) => { this.NotifyComplete(); }; streamer.SetSource(AudioTrackStreamer.mss); } }
/// <summary> /// Called when a new track requires audio decoding /// (typically because it is about to start playing) /// </summary> /// <param name="track"> /// The track that needs audio streaming /// </param> /// <param name="streamer"> /// The AudioStreamer object to which a MediaStreamSource should be /// attached to commence playback /// </param> /// <remarks> /// To invoke this method for a track set the Source parameter of the AudioTrack to null /// before setting into the Track property of the BackgroundAudioPlayer instance /// property set to true; /// otherwise it is assumed that the system will perform all streaming /// and decoding /// </remarks> protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer) { // Set the source of streamer to a media stream source double freq = Convert.ToDouble(track.Tag); // Use sine wave audio generator to simulate a streaming audio feed SineMediaStreamSource mss = new SineMediaStreamSource(freq, 1.0, TimeSpan.FromSeconds(5)); // Event handler for when a track is complete or the user switches tracks mss.StreamComplete += new EventHandler(mss_StreamComplete); // Set the source streamer.SetSource(mss); }
/// <summary> /// Called when a new track requires audio decoding /// (typically because it is about to start playing) /// </summary> /// <param name="track"> /// The track that needs audio streaming /// </param> /// <param name="streamer"> /// The AudioStreamer object to which a MediaStreamSource should be /// attached to commence playback /// </param> /// <remarks> /// To invoke this method for a track set the Source parameter of the AudioTrack to null /// before setting into the Track property of the BackgroundAudioPlayer instance /// property set to true; /// otherwise it is assumed that the system will perform all streaming /// and decoding /// </remarks> protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer) { lock (AudioTrackStreamer.syncRoot) { try { AudioTrackStreamer.mss = new ShoutcastMediaStreamSource(new Uri(track.Tag)); AudioTrackStreamer.mss.MetadataChanged += new RoutedEventHandler(AudioTrackStreamer.MetadataChanged); AudioTrackStreamer.mss.Closed += (s, e) => { this.NotifyComplete(); }; streamer.SetSource(AudioTrackStreamer.mss); } catch (Exception ex) { Debug.WriteLine("----------==============="); Debug.WriteLine("OnBeginStreaming:" + ex); } } }
async Task RunStreamingAsync(AudioTrack track, AudioStreamer streamer) { IMediaStreamFacade mediaStreamFacade = null; try { if (null == track || null == track.Tag) { Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() null url"); return; } Uri url; if (!Uri.TryCreate(track.Tag, UriKind.Absolute, out url)) { Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() invalid url: " + track.Tag); return; } var defaultTitle = "Unknown"; var mediaTrack = TrackManager.Tracks.Where(t => null != t).FirstOrDefault(t => t.Url == url); if (null != mediaTrack) defaultTitle = mediaTrack.Title; _metadataHandler.DefaultTitle = defaultTitle; if (!string.Equals(track.Title, defaultTitle)) { track.BeginEdit(); track.Title = defaultTitle; track.EndEdit(); } mediaStreamFacade = await InitializeMediaStreamAsync().ConfigureAwait(false); Debug.Assert(null != mediaStreamFacade); MediaStreamSource mss; if (null != mediaTrack) mss = await mediaStreamFacade.CreateMediaStreamSourceAsync(mediaTrack, _cancellationTokenSource.Token).ConfigureAwait(false); else mss = await mediaStreamFacade.CreateMediaStreamSourceAsync(url, _cancellationTokenSource.Token).ConfigureAwait(false); if (null == mss) { Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() unable to create media stream source"); } else { streamer.SetSource(mss); await mediaStreamFacade.PlayingTask.ConfigureAwait(false); return; } } catch (OperationCanceledException) { return; } catch (Exception ex) { Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() failed: " + ex.ExtendedMessage()); } if (null == mediaStreamFacade) return; await CleanupMediaStreamFacadeAsync(mediaStreamFacade).ConfigureAwait(false); }