zoukankan      html  css  js  c++  java
  • 如何在后台播放音乐

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    audioSession = [AVAudioSession sharedInstance];

    NSError *err = nil;

    UIDevice *device = [UIDevice currentDevice];

        BOOL backgroundSupported = NO;

    if ([device respondsToSelector:@selector(isMultitaskingSupported)]) {

    backgroundSupported = device.multitaskingSupported;

    }

    if (backgroundSupported) {

    NSLog(@"Supports multitasking");

    [audioSession setCategory :AVAudioSessionCategoryPlayback error:&err];

    }

    else {

    NSLog(@"Does not support multitasking");

    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];

    }

    if(err){

    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);

    }

    [audioSession setActive:YES error:&err];

    err = nil;

    if(err){

    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);

    }

        // Override point for customization after application launch.

        [self.window makeKeyAndVisible];


    return YES;

    }

     

    官方文档:

    http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html


  • 相关阅读:
    Vue异步数据交互 promise axios async fetch
    JS数组或对象转为JSON字符换 JavaScript JSON.stringify()
    JS返回数组的最大值与最小值
    Error: Cannot find module './application'
    Express框架
    NodeJS项目制作流程
    模板引擎art-template
    基于NodeJS的网络响应原理与HTTP协议
    leetcode 953. 验证外星语词典 做题笔记
    leetcode 771. 宝石与石头 做题笔记
  • 原文地址:https://www.cnblogs.com/qq78292959/p/2076928.html
Copyright © 2011-2022 走看看