我使用 ISimpleAudioPlayer 和 Libvlc 在 Xamarin 窗体项目中播放音频和视频。但对于 iOS,即使应用程序最小化或屏幕锁定,音频和视频仍在播放。我设法通过使用在android部分停止它:
protected override void OnDisappearing()
{
base.OnDisappearing();
if (_audioPlayer != null)
{
if (_audioPlayer.IsPlaying)
{
_audioPlayer.Stop();
}
}
}
// 视频
protected override void OnDisappearing()
{
myvideo.MediaPlayer.Stop();
base.OnDisappearing();
MessagingCenter.Send(this, "SetLandscapeModeOff");
MessagingCenter.Unsubscribe<HomeVideoPage>(this, "SetLandscapeModeOff");
}
我的 AppDelegate.cs 是:
namespace AppTemplateDS.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
LibVLCSharpFormsRenderer.Init();
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}
}
注意:后台模式功能在 iOS Xamarin 项目中已停用。
请帮忙