Is it possible to play sounds without stopping iPod music?

前端 未结 2 1152
无人共我
无人共我 2021-01-21 03:52

Is it possible to play sounds within an app without stopping iPod music?

Right now I\'m using the following, but it stops iPod music

soundPath =[[NSBundl         


        
相关标签:
2条回答
  • 2021-01-21 04:09

    Yes, or just

    AVAudioSession *audiosession = [AVAudioSession sharedInstance];
    [audiosession setCategory:AVAudioSessionCategoryAmbient error:nil];
    
    0 讨论(0)
  • 2021-01-21 04:31

    Yes you can, you could use the following code

    // setup session correctly
    AVAudioSession *audiosession = [AVAudioSession sharedInstance];
    [audiosession setCategory:AVAudioSessionCategoryPlayback error:nil];
    OSStatus propertySetError = 0;
    
    UInt32 mixingAllow = true;
    propertySetError = AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (mixingAllow),&mixingAllow);
    
    NSError *error = nil;
    [audiosession setActive:YES error:&error];
    
    // play sound
    NSURL *url = [NSURL fileURLWithPath:filePath];
    AVAudioPlayer *audioplayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&;error]autorelease];
    
    0 讨论(0)
提交回复
热议问题