Windows phone 7 如何在后台播放MediaElement。?
我正在开发一个通过流媒体播放在线广播的应用程序。我使用了MediaElement。但问题是播放器不在后台播放。我的意思是,只要我点击手机上的“开始”或“返回”按钮,流媒体和音频就会停止我没有在任何设备上测试过它,所以如果它发生在模拟器上,请通知我,但不是在设备上。这是我的代码Windows phone 7 如何在后台播放MediaElement。?,windows-phone-7,Windows Phone 7,我正在开发一个通过流媒体播放在线广播的应用程序。我使用了MediaElement。但问题是播放器不在后台播放。我的意思是,只要我点击手机上的“开始”或“返回”按钮,流媒体和音频就会停止我没有在任何设备上测试过它,所以如果它发生在模拟器上,请通知我,但不是在设备上。这是我的代码 private void Play() { if (mediaElement == null || mediaElement.CurrentState != MediaElementState.Pl
private void Play()
{
if (mediaElement == null || mediaElement.CurrentState != MediaElementState.Playing)
{
if (SystemTray.ProgressIndicator == null)
SystemTray.ProgressIndicator = new ProgressIndicator();
SystemTray.ProgressIndicator.IsIndeterminate = true;
SystemTray.ProgressIndicator.IsVisible = true;
SystemTray.ProgressIndicator.Text = "Connecting to *********...";
mediaStream = new ********.RadioStream(uri);
mediaStream.StreamSetupComplete += (o, e) =>
{
Dispatcher.BeginInvoke(() =>
{
if (mediaElement != null)
{
LayoutRoot.Children.Remove(mediaElement);
}
mediaElement = new MediaElement();
mediaElement.Volume = 1.0;
LayoutRoot.Children.Add(mediaElement);
mediaElement.SetSource(mediaStream);
SystemTray.ProgressIndicator.IsVisible = false;
});
};
}
}
我想知道让它在后台播放的步骤。至少当用户按下“开始”按钮时,音频流不应停止
还有一个问题是,我添加了一个ApplicationBarMenu,其中有一个“退出”按钮。用户单击此按钮后,流媒体应立即停止,应用程序应自行关闭。我无法以编程方式关闭应用程序。代码如下所示
void exit_Click(object sender, EventArgs e)
{
if (playing)
{
MessageBoxResult Choice;
Choice = MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel);
if (Choice == MessageBoxResult.OK)
{
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(@"Images/play.png", UriKind.Relative));
play.Background = brush;
Stop();
playing = false;
try
{
// if (NavigationService.CanGoBack)
// {
// while (NavigationService.RemoveBackEntry() != null)
// {
// NavigationService.RemoveBackEntry();
// }
// }
}
catch
{
}
}
else
{
}
}
}
请帮我输入正确的代码。即使除了MediaElement之外,还有其他方式在后台流媒体,也请建议。。
希望尽快得到答复。提前感谢大家 您必须为此使用
您也应该看看名称空间。请有人回答这个问题。我因此陷入了困境。