gpt4 book ai didi

ios - 单点触控远程控制事件不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:22 26 4
gpt4 key购买 nike

我想知道是否有 monotuch 的工作示例显示了接收远程控制事件(例如来自耳机按钮的事件)的工作示例。

我已经实现了一个单 View iphone 应用程序,实现了 CanBecomeFirstResponder,称为 BecomeFirstResponder 以及 UIApplication.SharedApplication.BeginReceivingRemoteControlEvents() 但我没有收到任何事件。

这是我的 SingleViewController 代码。

public partial class SingleViewViewController : UIViewController
{
public SingleViewViewController () : base ("SingleViewViewController", null)
{
}

public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();

// Release any cached data, images, etc that aren't in use.
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

// Perform any additional setup after loading the view, typically from a nib.
AVAudioSession audioSession = AVAudioSession.SharedInstance();
NSError error;
audioSession.SetCategory(AVAudioSession.CategoryPlayback, out error);
audioSession.SetActive(true,out error);

this.BecomeFirstResponder();
UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();
}

public override void ViewDidUnload ()
{
base.ViewDidUnload ();

// Clear any references to subviews of the main view in order to
// allow the Garbage Collector to collect them sooner.
//
// e.g. myOutlet.Dispose (); myOutlet = null;

ReleaseDesignerOutlets ();
}

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}

public override bool CanBecomeFirstResponder {
get {
return true;
}
}
public override bool CanResignFirstResponder {
get {
return false;
}
}

public override void RemoteControlReceived (UIEvent theEvent)
{
base.RemoteControlReceived (theEvent);
}
}

最佳答案

我在这方面花了一点时间,我想我可能会给你答案。我的第一个错误假设是 Remote (耳机)上的音量增大和减小控件会注册,但它们不会。

除了通过反复试验,我还没有设法确认以下内容,但看起来您需要让 AVAudioPlayer 播放一些东西,或者至少在您启动 AVAudioSession 时播放一些东西。在不播放任何内容的情况下,播放/停止事件将传递给处理它的音乐应用程序。

在您的代码中,在调用 base 之后的 ViewDidLoad 方法中,我添加了

AVAudioPlayer player = new AVAudioPlayer(new NSUrl("Music/test.m4a", false), null);
player.PrepareToPlay();
player.Play();

如果您在 GitHub 上查看这些示例的第 27 章,您将看到一个播放音频和处理远程控制事件的示例。

https://github.com/mattneub/Programming-iOS-Book-Examples

我无法在没有播放器播放的情况下使远程控制事件正常工作,您的示例与许多 Obj-C 样本相匹配,但我也无法在 Xcode 中使其正常工作。

希望这对您有所帮助。

关于ios - 单点触控远程控制事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com