不调用handleRemoteNowPlayingActivity [英] handleRemoteNowPlayingActivity is not called

查看:111
本文介绍了不调用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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