不调用handleRemoteNowPlayingActivity

编程入门 行业动态 更新时间:2024-10-23 15:32:57
本文介绍了不调用handleRemoteNowPlayingActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何启动handleRemoteNowPlayingActivity函数的调用.

How to initiate call of handleRemoteNowPlayingActivity function.

我尝试在iPhone应用程序中使用 AVAudioPlayer 播放音频文件,并且希望在手表上调用此功能.

I try to play an audio file with AVAudioPlayer in my iPhone app and I expect that this function will be called on watches.

也许我应该再打一些电话来触发此功能?除了Apple文档中所说的内容,我找不到有关此方法的任何其他信息.

Maybe I should make some additional call to trigger this function? I cannot find any additional information about this method except what is said in the apple documentation.

也许有人遇到了这个问题,将能够为我提供帮助.

Maybe someone faced this problem and will be able to help me.

初始化音频播放器的代码.

Code of initialization audio player.

@IBAction func play(_ sender: Any) { let url = URL(string: Bundle.main.path(forResource: "music", ofType: "mp3") ?? "")! do { try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .mixWithOthers) try AVAudioSession.sharedInstance().setActive(true) player = try AVAudioPlayer(contentsOf: url) } catch let error { print(error) } player?.play() }

推荐答案

我找到了答案.

如果您要在手表应用中启动 handleRemoteNowPlayingActivity ,则应

If you want to initiate handleRemoteNowPlayingActivity in your watch app, you should

  • 在设备上播放一些音频/视频

  • play some audio/video on your device

设置音频会话,如上所示

setup audio session as shown above

,然后调用beginReceivingRemoteControlEvents().

and call beginReceivingRemoteControlEvents().

更多推荐

不调用handleRemoteNowPlayingActivity

本文发布于:2023-10-28 19:19:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537546.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:handleRemoteNowPlayingActivity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!