本文整理汇总了C#中SystemMediaTransportControls类的典型用法代码示例。如果您正苦于以下问题:C# SystemMediaTransportControls类的具体用法?C# SystemMediaTransportControls怎么用?C# SystemMediaTransportControls使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SystemMediaTransportControls类属于命名空间,在下文中一共展示了SystemMediaTransportControls类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartMediaElement
private async void StartMediaElement()
{
// To use AudioCategory.BackgroundCapableMedia:
// * OnWindows 8 set MediaControl.PlayPressed, MediaControl.PausePressed,
// MediaControl.PlayPauseTogglePressed and MediaControl.StopPressed.
// * On Windows 8.1 set SystemMediaTransportControls.ButtonPressed.
systemControls = SystemMediaTransportControls.GetForCurrentView();
systemControls.ButtonPressed += OnButtonPressed;
systemControls.IsPlayEnabled = true;
systemControls.IsPauseEnabled = true;
systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;
mediaPlayer = new MediaElement();
mediaPlayer.AudioCategory = AudioCategory.BackgroundCapableMedia;
mediaPlayer.AutoPlay = true;
mediaPlayer.CurrentStateChanged += OnCurrentStateChanged;
this.Content = mediaPlayer;
HttpClient client = new HttpClient();
// Add custom headers or credentials.
client.DefaultRequestHeaders.Add("Foo", "Bar");
//Uri uri = new Uri("http://localhost/song.mp3?slow=1000&?bufferlength=100000&lastModified=true");
Uri uri = new Uri("http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4");
HttpRandomAccessStream stream = await HttpRandomAccessStream.CreateAsync(client, uri);
// If you need to use HttpClient, use MediaElement.SetSource() instead of MediaElement.Source.
mediaPlayer.SetSource(stream, stream.ContentType);
}
示例2: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
mdcontrol = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
mdcontrol.IsEnabled = true;
// 允许使用播放/暂停按钮
mdcontrol.IsPlayEnabled = true;
mdcontrol.IsPauseEnabled = true;
// 处理ButtonPressed事件
mdcontrol.ButtonPressed += mdcontrol_ButtonPressed;
// 获取MediaPlayer实例
currentPlayer = BackgroundMediaPlayer.Current;
// 处理事件,接收来自前台应用程序的消息
BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;
// 关闭自动开始播放
currentPlayer.AutoPlay = false;
// 设置播放源
Uri audioUri = new Uri("ms-appx:///Assets/1.mp3");
currentPlayer.SetUriSource(audioUri);
deferral = taskInstance.GetDeferral();
// 当后台任务被取消时引发事件
taskInstance.Canceled += task_Canceled;
isRunning = true;
}
示例3: MainPage
public MainPage()
{
this.InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Enabled;
// Register for the window resize event
Window.Current.SizeChanged += WindowSizeChanged;
// Source for WebControl || XAML
songInformation.Source = new Uri("ms-appx-web:///HTML code/SongInformation.html");
previousSongInformation.Source = new Uri("ms-appx-web:///HTML code/PreviousSongs_Larger.html");
MenuWebView.Navigate(new Uri("http://vocaloidradio.com/"));
currentPage.Text = "Vocaloid Radio";
// Hook up app to system transport controls.
mediaControl = SystemMediaTransportControls.GetForCurrentView();
mediaControl.ButtonPressed += medialControl_ButtonPressed;
// Register to handle the following system transpot control buttons.
mediaControl.IsPlayEnabled = true;
mediaControl.IsPauseEnabled = true;
mediaControl.IsFastForwardEnabled = false;
mediaControl.IsNextEnabled = false;
mediaControl.IsPreviousEnabled = false;
mediaControl.IsRewindEnabled = false;
mediaControl.IsChannelDownEnabled = false;
mediaControl.IsChannelUpEnabled = false;
mediaControl.IsRecordEnabled = false;
}
示例4: Run
/// <summary>
/// Performs the work of a background task. The system calls this method when the associated
/// background task has been triggered.
/// </summary>
/// <param name="taskInstance">
/// An interface to an instance of the background task. The system creates this instance when the
/// task has been triggered to run.
/// </param>
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting");
this.systemMediaTransportControl = SystemMediaTransportControls.GetForCurrentView();
this.systemMediaTransportControl.IsEnabled = true;
this.systemMediaTransportControl.IsPauseEnabled = true;
this.systemMediaTransportControl.IsPlayEnabled = true;
this.systemMediaTransportControl.IsNextEnabled = true;
this.systemMediaTransportControl.IsPreviousEnabled = true;
// Wire up system media control events
this.systemMediaTransportControl.ButtonPressed += this.OnSystemMediaTransportControlButtonPressed;
this.systemMediaTransportControl.PropertyChanged += this.OnSystemMediaTransportControlPropertyChanged;
// Wire up background task events
taskInstance.Canceled += this.OnTaskCanceled;
taskInstance.Task.Completed += this.OnTaskcompleted;
// Initialize message channel
BackgroundMediaPlayer.MessageReceivedFromForeground += this.OnMessageReceivedFromForeground;
// Notify foreground that we have started playing
BackgroundMediaPlayer.SendMessageToForeground(new ValueSet() { { "BackgroundTaskStarted", "" } });
this.backgroundTaskStarted.Set();
this.backgroundTaskRunning = true;
this.deferral = taskInstance.GetDeferral();
}
示例5: MainPage_Loaded
async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
this.systemControls = SystemMediaTransportControls.GetForCurrentView();
this.systemControls.ButtonPressed += systemControls_ButtonPressed;
this.systemControls.IsPlayEnabled = true;
this.systemControls.IsPauseEnabled = true;
this.renderer = await AudioRenderer.CreateAsync();
var rootPath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "\\Sounds\\";
this.drumPad = new DrumPad();
this.drumPad.SetDrumSound(DrumKind.Bass, rootPath + "Drum-Bass.wav");
this.drumPad.SetDrumSound(DrumKind.Snare, rootPath + "Drum-Snare.wav");
this.drumPad.SetDrumSound(DrumKind.Shaker, rootPath + "Drum-Shaker.wav");
this.drumPad.SetDrumSound(DrumKind.ClosedHiHat, rootPath + "Drum-Closed-Hi-Hat.wav");
this.drumPad.SetDrumSound(DrumKind.Cowbell, rootPath + "Cowbell.wav");
this.drumPad.SetDrumSound(DrumKind.OpenHiHat, rootPath + "Drum-Open-Hi-Hat.wav");
this.drumPad.SetDrumSound(DrumKind.RideCymbal, rootPath + "Drum-Ride-Cymbal.wav");
this.drumPad.SetDrumSound(DrumKind.FloorTom, rootPath + "developer_loud.wav");
this.drumPad.SetDrumSound(DrumKind.HighTom, rootPath + "satya_fantastic.wav");
this.oscillator = new Oscillator();
this.looper = new Looper();
this.demultiplexer = new AudioDemultiplexer();
this.looper.ListenTo(this.drumPad);
this.demultiplexer.ListenTo(this.looper);
this.demultiplexer.ListenTo(this.oscillator);
this.renderer.ListenTo(this.demultiplexer);
Play();
}
示例6: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
// Enable system transport controls for the current view.
_systemMediaTransportControl = SystemMediaTransportControls.GetForCurrentView();
_systemMediaTransportControl.IsEnabled = true;
_systemMediaTransportControl.IsPauseEnabled = true;
_systemMediaTransportControl.IsPlayEnabled = true;
_systemMediaTransportControl.ButtonPressed += MediaTransportControlButtonPressed;
// Handle events
BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;
BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
BackgroundMediaPlayer.Current.BufferingStarted += Current_BufferingStarted;
BackgroundMediaPlayer.Current.MediaFailed += Current_MediaFailed;
// Handle the closing of the background task correctly
taskInstance.Canceled += taskInstance_Canceled;
taskInstance.Task.Completed += Task_Completed;
_deferral = taskInstance.GetDeferral();
// TODO: load _nowPlaying from app settings
if (ApplicationData.Current.LocalSettings.Values.ContainsKey("CurrentStation"))
{
_nowPlaying = ApplicationData.Current.LocalSettings.Values["CurrentStation"].ToString();
//ApplicationData.Current.LocalSettings.Values.Remove("NowPlaying");
}
_BackgroundStarted.Set();
_isBackgroundTaskRunning = true;
// END
Debug.WriteLine("BackgroundAudioTask - Started");
}
示例7: OnActivate
/// <inheritdoc />
protected override bool OnActivate()
{
if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
SystemControls = SystemMediaTransportControls.GetForCurrentView();
SystemControls.ButtonPressed += SystemControls_ButtonPressed;
RefreshFastForwardState();
RefreshRewindState();
RefreshStopState();
RefreshPlayState();
RefreshPauseState();
RefreshNextState();
RefreshPreviousState();
RefreshPlaybackStatus();
if (PlaylistPlugin != null)
{
PlaylistPlugin.Playlist.CollectionChanged += Playlist_CollectionChanged;
PlaylistPlugin.CurrentPlaylistItemChanged += PlaylistPlugin_CurrentPlaylistItemChanged;
}
WireEvents(MediaPlayer.InteractiveViewModel);
MediaPlayer.InteractiveViewModelChanged += MediaPlayer_InteractiveViewModelChanged;
return true;
}
else return false;
}
示例8: MediaPlayer
public MediaPlayer()
{
//Initialize Page
this.InitializeComponent();
//NavigationHelper
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
this.NavigationCacheMode = NavigationCacheMode.Required;
//Load Settings
MPS_Start_Settings();
//Register to handle the following system transpot control buttons.
systemControls = SystemMediaTransportControls.GetForCurrentView();
systemControls.ButtonPressed += SystemMediaControls_ButtonPressed;
systemControls.IsPlayEnabled = true;
systemControls.IsPauseEnabled = true;
systemControls.IsStopEnabled = true;
systemControls.IsNextEnabled = true;
systemControls.IsPreviousEnabled = true;
systemControls.IsEnabled = true;
DC.Trace("(MediaPlayer Loaded)");
SetupTimer();
}
示例9: Run
/// <summary>
/// The Run method is the entry point of a background task.
/// </summary>
/// <param name="taskInstance"></param>
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
// Initialize SMTC object to talk with UVC.
//Note that, this is intended to run after app is paused and
//hence all the logic must be written to run in background process
systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
systemmediatransportcontrol.IsEnabled = true;
systemmediatransportcontrol.IsPauseEnabled = true;
systemmediatransportcontrol.IsPlayEnabled = true;
systemmediatransportcontrol.IsNextEnabled = true;
systemmediatransportcontrol.IsPreviousEnabled = true;
// Associate a cancellation and completed handlers with the background task.
taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
taskInstance.Task.Completed += Taskcompleted;
var value = ApplicationSettingsHelper.ReadResetSettingsValue(Constants.AppState);
if (value == null)
foregroundAppState = ForegroundAppStatus.Unknown;
else
foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());
//Add handlers for MediaPlayer
BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
deferral = taskInstance.GetDeferral();
}
示例10: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
mediaTransportControls = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
mediaTransportControls.ButtonPressed += MediaButtonPressed;
mediaTransportControls.PropertyChanged += MediaPropertyChanged;
mediaTransportControls.IsEnabled = true;
mediaTransportControls.IsPauseEnabled = true;
mediaTransportControls.IsPlayEnabled = true;
mediaTransportControls.IsNextEnabled = true;
mediaTransportControls.IsPreviousEnabled = true;
BackgroundMediaPlayer.Current.CurrentStateChanged += MediaPlayerStateChanged;
messageTransport.PlaybackRequested += OnPlaybackRequested;
messageTransport.Start();
messageTransport.NotifyForeground();
deferral = taskInstance.GetDeferral();
backgroundTaskStarted.Set();
taskInstance.Task.Completed += TaskCompleted;
taskInstance.Canceled += OnCanceled;
}
示例11: MediaButtonPressed
private void MediaButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
{
switch (args.Button)
{
case SystemMediaTransportControlsButton.Play:
BackgroundMediaPlayer.SendMessageToForeground(new ValueSet
{
{"command", PlaybackCommand.Play.ToString()}
});
break;
case SystemMediaTransportControlsButton.Pause:
case SystemMediaTransportControlsButton.Stop:
BackgroundMediaPlayer.SendMessageToForeground(new ValueSet
{
{"command", PlaybackCommand.Pause.ToString()}
});
break;
case SystemMediaTransportControlsButton.Previous:
BackgroundMediaPlayer.SendMessageToForeground(new ValueSet
{
{"command", PlaybackCommand.Previous.ToString()}
});
break;
case SystemMediaTransportControlsButton.Next:
BackgroundMediaPlayer.SendMessageToForeground(new ValueSet
{
{"command", PlaybackCommand.Next.ToString()}
});
break;
}
}
示例12: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
smtc = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
smtc.ButtonPressed += Smtc_ButtonPressed;
smtc.PropertyChanged += Smtc_PropertyChanged;
smtc.IsEnabled = true;
smtc.IsPauseEnabled = true;
smtc.IsPlayEnabled = true;
smtc.IsNextEnabled = true;
smtc.IsPreviousEnabled = true;
var value = ApplicationSettingsHelper.ReadResetSettingsValue(ApplicationSettingsConstants.AppState);
if (value == null)
foregroundAppState = AppState.Unknown;
else
foregroundAppState = EnumHelper.Parse<AppState>(value.ToString());
BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;
if (foregroundAppState != AppState.Suspended)
MessageService.SendMessageToForeground(new BackgroundTaskStateChangedMessage(BackgroundTaskState.Running));
ApplicationSettingsHelper.SaveSettingsValue(ApplicationSettingsConstants.BackgroundTaskState, BackgroundTaskState.Running.ToString());
deferral = taskInstance.GetDeferral(); // This must be retrieved prior to subscribing to events below which use it
ReadytoConfirmFiles();
// Mark the background task as started to unblock SMTC Play operation (see related WaitOne on this signal)
taskInstance.Task.Completed += TaskCompleted;
taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
}
示例13: Run
/// <summary>
/// The Run method is the entry point of a background task.
/// </summary>
/// <param name="taskInstance"></param>
public void Run(IBackgroundTaskInstance taskInstance)
{
try
{
Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
// Initialize SMTC object to talk with UVC.
//Note that, this is intended to run after app is paused and
//hence all the logic must be written to run in background process
systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
systemmediatransportcontrol.IsEnabled = true;
systemmediatransportcontrol.IsPauseEnabled = true;
systemmediatransportcontrol.IsPlayEnabled = true;
systemmediatransportcontrol.IsNextEnabled = true;
systemmediatransportcontrol.IsPreviousEnabled = true;
// Associate a cancellation and completed handlers with the background task.
taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
taskInstance.Task.Completed += Taskcompleted;
var value = ApplicationSettingsHelper.ReadResetSettingsValue(BackgroundAudioConstants.AppState);
if (value == null)
foregroundAppState = ForegroundAppStatus.Unknown;
else
foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());
//Add handlers for MediaPlayer
BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
//Add handlers for playlist trackchanged
Playlist.TrackChanged += playList_TrackChanged;
//Initialize message channel
BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;
//Send information to foreground that background task has been started if app is active
if (foregroundAppState != ForegroundAppStatus.Suspended)
{
ValueSet message = new ValueSet();
message.Add(BackgroundAudioConstants.BackgroundTaskStarted, "");
BackgroundMediaPlayer.SendMessageToForeground(message);
}
BackgroundTaskStarted.Set();
backgroundtaskrunning = true;
Playlist.PopulatePlaylist();
var currentTrackIndex = ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);
if (currentTrackIndex != null)
{
Playlist.CurrentTrack = (int)currentTrackIndex;
}
ApplicationSettingsHelper.SaveSettingsValue(BackgroundAudioConstants.BackgroundTaskState, BackgroundAudioConstants.BackgroundTaskRunning);
deferral = taskInstance.GetDeferral();
}
catch
{
}
}
示例14: MediaTransportService
public MediaTransportService(SystemMediaTransportControls smtc)
{
_smtc = smtc;
PlaybackStatus = MediaPlaybackStatus.Closed;
_smtc.DisplayUpdater.Type = MediaPlaybackType.Music;
_smtc.DisplayUpdater.Update();
_smtc.ButtonPressed += _smtc_ButtonPressed;
}
示例15: InitializeSystemMediaControls
private void InitializeSystemMediaControls()
{
systemPlayerControls = SystemMediaTransportControls.GetForCurrentView();
systemPlayerControls.ButtonPressed += SystemControls_ButtonPressed;
systemPlayerControls.IsPlayEnabled = true;
systemPlayerControls.IsPauseEnabled = true;
}