不调用 handleRemoteNowPlayingActivity [英] handleRemoteNowPlayingActivity is not called

查看:38
本文介绍了不调用 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.

也许我应该做一些额外的调用来触发这个功能?除了苹果文档中所说的之外,我找不到有关此方法的任何其他信息.

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

如上所示设置音频会话

并调用 beginReceivingRemoteControlEvents().

and call beginReceivingRemoteControlEvents().

这篇关于不调用 handleRemoteNowPlayingActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆