zoukankan      html  css  js  c++  java
  • iPhone音频播放后台控制

    ipod等播放程序在后台时,双击HOME键,会有个控制界面,如上图,可以使用它进行播放控制。

    如果需要直接使用多媒体控制键控制自己程序后台播放的音乐:

    首先在viewdidload等初始化的地方声明App接收远程控制事件,并在相应地方结束声明

    - (void) viewWillAppear:(BOOL)animated  

    {  

      [super viewWillAppear:animated];  

      [UIApplication sharedApplication] beginReceivingRemoteControlEvents];  

      [self becomeFirstResponder];  

    - (void) viewWillDisappear:(BOOL)animated  

    {  

      [super viewWillDisappear:animated];  

      [UIApplication sharedApplication] endReceivingRemoteControlEvents];  

      [self resignFirstResponder];  

    }

    将本程序设为第一接收者

    - (BOOL)canBecomeFirstResponder  

    {  

      return YES;  

    }

     最后定义 remoteControlReceivedWithEvent,处理具体的播放、暂停、前进、后退等具体事件

    - (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent 

    {      

         if (receivedEvent.type == UIEventTypeRemoteControl) 

      {  

            switch (receivedEvent.subtype) 

          {  

               case UIEventSubtypeRemoteControlTogglePlayPause:  

                  [self playButtonPressed:playButton];  

                  [self testing];  

                    break;

                case UIEventSubtypeRemoteControlPreviousTrack:  

                     [self rewButtonReleased:(UIButton *)rewButton];  

                   break;  

               case UIEventSubtypeRemoteControlNextTrack:  

                     [self ffwButtonReleased:(UIButton *)ffwButton];  

                     break;  

                default:  

                     break;  

            }  

        }  

    }  

    这样就能直接使用多媒体控制键控制自己程序后台播放的音乐了

          by -yuzhang2

  • 相关阅读:
    Linux硬盘分区方案
    mysql笔记四:索引查询及处理
    thread 学习笔记
    mysql笔记二:基本数据库、表查询操作
    linux 自学系列:监测端口占用情况
    linux 自学系列:命令行传输文件
    mysql笔记三:基本数据库、表创建更新操作
    mysql笔记五:权限管理
    threading源代码问题,为什么要将引入的变量del?
    linux 自学系列:更改系统语言编码
  • 原文地址:https://www.cnblogs.com/ydhliphonedev/p/2523918.html
Copyright © 2011-2022 走看看