本文整理汇总了C#中AudioTrack.BeginEdit方法的典型用法代码示例。如果您正苦于以下问题:C# AudioTrack.BeginEdit方法的具体用法?C# AudioTrack.BeginEdit怎么用?C# AudioTrack.BeginEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioTrack
的用法示例。
在下文中一共展示了AudioTrack.BeginEdit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunStreamingAsync
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);
}
示例2: OnPlayStateChanged
/// <summary>
/// Called when the playstate changes, except for the Error state (see OnError)
/// </summary>
/// <param name="player">The BackgroundAudioPlayer</param>
/// <param name="track">The track playing at the time the playstate changed</param>
/// <param name="playState">The new playstate of the player</param>
/// <remarks>
/// Play State changes cannot be cancelled. They are raised even if the application
/// caused the state change itself, assuming the application has opted-in to the callback.
///
/// Notable playstate events:
/// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
/// (b) TrackReady: an audio track has been set and it is now ready for playack.
///
/// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
/// </remarks>
protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
{
switch (playState)
{
case PlayState.TrackEnded:
if (currentPlaylist.Count > 0)
player.Track = GetNextTrack();
break;
case PlayState.TrackReady:
track.BeginEdit();
track.Title = currentPlaylist[currentTrackNumber].Title;
track.EndEdit();
player.Play();
break;
case PlayState.Shutdown:
// TODO: Handle the shutdown state here (e.g. save state)
player.Close();
break;
case PlayState.Unknown:
break;
case PlayState.Stopped:
break;
case PlayState.Paused:
break;
case PlayState.Playing:
break;
case PlayState.BufferingStarted:
track.BeginEdit();
track.Title = "Buffering...";
track.EndEdit();
break;
case PlayState.BufferingStopped:
track.BeginEdit();
track.Title = currentPlaylist[currentTrackNumber].Title;
track.EndEdit();
break;
case PlayState.Rewinding:
track.BeginEdit();
track.Title = "Rewinding...";
track.EndEdit();
break;
case PlayState.FastForwarding:
track.BeginEdit();
track.Title = "FastForwarding...";
track.EndEdit();
break;
}
NotifyComplete();
}