-->

在一个可控的TabBar iOS应用程序在第二个选项卡进行交互时,接收到RemoteControlE

2019-09-17 21:15发布

我开发了标签栏控制器中的iOS应用。 在第一个选项卡,我把AVQueuePlayer的一个实例,开始从网络播放音乐。 我做了所有的编码,允许播放和暂停通过遥控器事件的事件。 但我只能够接收远程控制的事件时,我留在第一个选项卡。 当我切换到其他标签,遥控事件没有接收到所述第一标签。

当我把在第一个选项卡的视图控制器以下行,可以接收远程控制事件以第一个选项卡,即使我留在第二个标签。

- (BOOL)canResignFirstResponder
{
    return NO;
}

但我与用户有互动的其他一些意见文本字段。 如果不辞职第一响应者在第一个选项卡,我不能在其他选项卡输入文本。

请帮我,我怎么能处理的远程控制事件来控制在第一个选项卡的AVQueuePlayer实例,同时我的用户在第二个选项卡的应用程序进行交互?

谢谢你的帮助 !

Answer 1:

好。 我想它自己。

我创建了一个全局变量在执行文件的启动的avqueueplayer。 分配并开始在viewDidLoad方法的AVQueuePlayer。 创建一个类的方法来处理该怎么在播放和暂停的情况下做的。 并要求在其他视图控制器此类方法来直接从这些视图控制器处理远程控制事件。 这里是什么,我编写了一个例子:

//playerView header file

@interface playerView : UIViewController

+ (void)togglePlayPause;

@end

//playerView Implementation File

#import "playerView.h"

@interface playerView ()
@end

@implementation playerView

AVQueuePlayer *player;

- (void)viewDidLoad
{
[super viewDidLoad];
player = [[AVQueuePlayer alloc] initWithPlayerItem:[AVPlayerItem playerItemWithURL: someurl]];
}

+ (void) togglePlayPause
{
    if (player.rate == 1.0)
    {
        [player pause];
    }
    else if ((player.rate == 0.0) && ([player status]!= 2))
    {
        [player play];
    }
}

// include all other methods to handle remote control events as laid in apple documentation

@end



//otherView Implementation file

#include "playerView.h"


@interface otherView ()

@end

@implementation otherView

// include all other methods to handle remote control events as laid in apple documentation

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent
{

    if (receivedEvent.type == UIEventTypeRemoteControl) {

        switch (receivedEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                [playerView togglePlayPause];
                break;
            default:
                break;
        }
    }
}

@end

对于苹果文档中的所有铺设其他方法来处理远程控制事件是指:

事件处理指南适用于iOS -多媒体遥控器



文章来源: Receiving RemoteControlEvents to First Tab when interacting in Second Tab in a TabBar Controlled iOS App