オーディオ広告でバックグラウンドを再生する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このガイドは、IMA SDK の実装にオーディオ広告再生のバックグラウンド再生機能を追加したいと考えている iOS パブリッシャー様を対象としています。これにより、アプリはバックグラウンドで広告をリクエストできます。また、アプリがバックグラウンドに移り、広告の再生を最後まで継続することもできます。
動画広告をバックグラウンドで再生することはおすすめしません。
前提条件
- IMA SDK が実装された iOS アプリ
- IMA SDK V3 ベータ版 v13 以降。
参考情報
それでもアプリに IMA SDK を実装する必要がある場合は、スタートガイドをご覧ください。
アプリにバックグラウンド再生を追加する
バックグラウンド再生を追加する手順は次のとおりです。
- バックグラウンド モードの [Audio and Airplay] を有効にします。Xcode 6 で、ターゲットを選択し、[Capabilities] >Background Modes については、[音声と AirPlay] を有効にします。
AVAudioSession
を有効化し、そのカテゴリに、バックグラウンド音声を再生できる AVAudioSessionCategory
(AVAudioSessionCategoryPlayback
など)を設定します。
- (void)viewDidLoad {
[super viewDidLoad];
NSError *error;
[[AVAudioSession sharedInstance] setActive:YES error:&error];
if (error != nil) {
NSLog(@"Error: %@", error.localizedDescription);
}
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
if (error != nil) {
NSLog(@"Error: %@", error.localizedDescription);
}
}
IMAAdsLoader
を作成し、enableBackgroundPlayback
を YES
に設定して IMASettings
オブジェクトを渡します。
IMASettings *settings = [[IMASettings alloc] init];
settings.enableBackgroundPlayback = YES;
IMAAdsLoader *adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];
重要
バックグラウンドで広告リクエストを行うには、コンテンツが再生されている必要があります。そのため、アプリがバックグラウンドに入る前に、[IMAAdsLoader requestAds:]
を呼び出す前にコンテンツ プレーヤーで play を手動で呼び出すことが必要になる場合があります。
iOS アプリをバックグラウンドにすると、広告の再生が自動的に一時停止します。広告の再生中にアプリがバックグラウンドで実行されている場合、再生を再開するには [IMAAdsManager resume]
を呼び出す必要があります。
よくある質問
- アプリで音声と AirPlay のバックグラウンド モード機能を有効にしないとどうなりますか?
- このモードを選択しない場合、アプリがバックグラウンドに移行したときにアプリが再生している音声はすべて停止します。また、バックグラウンドで音声を起動することもできません。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-31 UTC。
[null,null,["最終更新日 2025-08-31 UTC。"],[[["\u003cp\u003eThis guide helps iOS publishers add background audio ad playback to their IMA SDK implementation.\u003c/p\u003e\n"],["\u003cp\u003eRequires iOS application with IMA SDK V3 Beta v13 or greater.\u003c/p\u003e\n"],["\u003cp\u003eEnable "Audio and Airplay" background mode in Xcode and activate \u003ccode\u003eAVAudioSession\u003c/code\u003e for background audio playback.\u003c/p\u003e\n"],["\u003cp\u003eCreate an \u003ccode\u003eIMAAdsLoader\u003c/code\u003e with \u003ccode\u003eenableBackgroundPlayback\u003c/code\u003e set to \u003ccode\u003eYES\u003c/code\u003e in \u003ccode\u003eIMASettings\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eBackgrounding pauses ad playback; resume with \u003ccode\u003e[IMAAdsManager resume]\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Play background in audio ads\n\nThis guide is intended for iOS publishers interested in adding background **audio** ad playback to their IMA SDK implementation. This allows the app to request ads in the background. It also allow the app to enter the background and continue to play an ad to completion.\n\nWe do not recommend playing video ads in the background.\n\nPrerequisites\n-------------\n\n\u003cbr /\u003e\n\n- iOS application with the IMA SDK implemented.\n- IMA SDK V3 Beta v13 or greater.\n\n\u003cbr /\u003e\n\nHelpful primers\n---------------\n\nIf you still need to implement the IMA SDK in your app, check out our [Get Started guide](/interactive-media-ads/docs/sdks/ios/client-side).\n\nAdding background ad playback to your app\n-----------------------------------------\n\nAdding background ad playback takes the following steps:\n\n1. Enable the **Audio and Airplay** background mode. In Xcode 6, select a target, then under **Capabilities \\\u003e Background Modes**, enable \"Audio and Airplay\".\n2. Activate the `AVAudioSession`, and set its category with an `AVAudioSessionCategory` that can play background audio, such as `AVAudioSessionCategoryPlayback`. \n\n```objective-c\n- (void)viewDidLoad {\n [super viewDidLoad];\n\n NSError *error;\n [[AVAudioSession sharedInstance] setActive:YES error:&error];\n if (error != nil) {\n NSLog(@\"Error: %@\", error.localizedDescription);\n }\n\n [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];\n if (error != nil) {\n NSLog(@\"Error: %@\", error.localizedDescription);\n }\n}\n```\n3. Create an `IMAAdsLoader`, passing in an `IMASettings` object with `enableBackgroundPlayback` set to `YES`. \n\n```objective-c\n IMASettings *settings = [[IMASettings alloc] init];\n settings.enableBackgroundPlayback = YES;\n IMAAdsLoader *adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];\n```\n\nImportant\n---------\n\nTo make background ad requests, your content must be playing. This may require manually calling play on the content player when the app enters the background before calling `[IMAAdsLoader requestAds:]`.\n\nBackgrounding an iOS app automatically pauses ad playback. If your app is backgrounded while playing an ad, you need to call `[IMAAdsManager resume]` to resume playback.\n\nFAQ\n---\n\nWhat happens if I don't enable the Audio and Airplay background mode capability in my app?\n: If you don't select this mode, any audio being played by the app stops when the app moves to the background. The app is also not able to launch any audio while backgrounded."]]