{"id":1086,"date":"2013-10-17T23:02:32","date_gmt":"2013-10-17T14:02:32","guid":{"rendered":"https:\/\/ecoop.net\/memo\/?p=1086"},"modified":"2026-08-10T14:48:33","modified_gmt":"2026-08-10T05:48:33","slug":"ios_play_sounds_and_background_music_simultaneously","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/ios_play_sounds_and_background_music_simultaneously.html","title":{"rendered":"\u3010iOS\u3011\u97f3\u697d\u3092\u6b62\u3081\u305a\u306b\u52b9\u679c\u97f3\u3092\u540c\u6642\u306b\u518d\u751f\u3059\u308b\u306b\u306f"},"content":{"rendered":"<p>\n\tiOS\u3067\u306f\u97f3\u3092\u518d\u751f\u3059\u308b\u6642\u306e\u9078\u629e\u80a2\u3068\u3057\u3066 MediaPlayer Farmework \u3068 AVFoundation Framework\u306e\uff12\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3053\u308c\u3089\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u591a\u91cd\u518d\u751f\u304c\u3067\u304d\u306a\u3044\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<h2>AVAudioPlayer + AVAudioPlayer\u3067\u540c\u6642\u518d\u751f<\/h2>\n<p>AVAudioPlayer\u3067\u306f\u97f3\u3092\u540c\u6642\u518d\u751f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3053\u306e\u969b\u6ce8\u610f\u70b9\u3068\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u5f62\u5f0f\u306f\u4e00\u822c\u7684\u306a.mp3\u3084.3gp\u3060\u3068\u540c\u6642\u518d\u751f\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u540c\u6642\u518d\u751f\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f.caf\u5f62\u5f0f\u3068\u3044\u3046Apple\u72ec\u81ea\u306e\u5f62\u5f0f\u306b\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>MP3\u306a\u3069\u304b\u3089 caf \u30d5\u30a1\u30a4\u30eb\u3078\u306e\u5909\u63db\u306fMac\u306a\u3089\u30bf\u30fc\u30df\u30ca\u30eb\u304b\u3089\u7c21\u5358\u306b\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"> $ afconvert -f caff -d 0 &quot;\u5143\u30d5\u30a1\u30a4\u30eb.mp3&quot; &quot;\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb.caf&quot;; <\/pre>\n<p> \u518d\u751f\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002mp3\u304b\u3089caf\u306b\u5909\u3048\u308b\u3060\u3051\u3067\u3059\u306d\u3002 <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\"> \r\n@implementation MySoundPlayer {\r\n    AVAudioPlayer* _player;\r\n}\r\n- (void) playSounds{\r\n    \/\/ music.caf \u3092\u518d\u751f\r\n    &#x5B;self playSoundWithFile: @&quot;music&quot; ofType: @&quot;caf&quot;]; \r\n    \/\/ sound.caf \u3092\u540c\u6642\u518d\u751f\r\n    &#x5B;self playSoundWithFile: @&quot;sound&quot; ofType: @&quot;car&quot;]; }\r\n- (void) playSoundWithFile:(NSString*)file ofType:(NSString*) type {\r\n    NSString* path = &#x5B;&#x5B;NSBundle mainBundle] pathForResource:file ofType:type];\r\n    NSURL* url = &#x5B;NSURL fileURLWithPath:path];\r\n    _player =&#x5B; &#x5B;AVAudioPlayer alloc] initWithContentsOfURL:url error:nil ];\r\n    &#x5B;_player prepareToPlay];\r\n    &#x5B;_player play];\r\n    }\r\n@end\r\n<\/pre>\n<p><\/p>\n<h3>MPMusicPlayerPlayer + MPMusicPlayerPlayer\u3067\u540c\u6642\u518d\u751f<\/h3>\n<p>MPMusicPlayerPlayer\u306f\u540c\u6642\u518d\u751f\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u6b8b\u5ff5\u3002<\/p>\n<p><\/p>\n<h3>MPMusicPlayerPlayer + AVAudioPlayer\u3067\u540c\u6642\u518d\u751f<\/h3>\n<p>\n\tMPMusicPlayerPlayer\u540c\u58eb\u306e\u540c\u6642\u518d\u751f\u306b\u306f\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u3001\u306a\u3089AVAudioPlayer\u3068\u306e\u7d44\u307f\u5408\u308f\u305b\u306f\u3069\u3046\u306a\u306e\u304b\uff1f\n<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u8a66\u884c\u932f\u8aa4\u3057\u305f\u7d50\u679c\u3001\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u307e\u307e\u3060\u3068\u5f8c\u308d\u306e\u97f3\u304c\u6d88\u3048\u3066\u3057\u307e\u3044\u3001\u540c\u6642\u518d\u751f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u3068\u3053\u308d\u304c\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092AppDelegate.m\u306b\u5165\u308c\u308b\u3068\u2026<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\r\n    \/\/ \u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u306e\u97f3\u306e\u518d\u751f\u3092\u8a31\u53ef\r\n    &#x5B;&#x5B;AVAudioSession sharedInstance] \r\n        setCategory:AVAudioSessionCategoryAmbient error:nil];\r\n}\r\n<\/pre>\n<p>\u3042\u3089\u4e0d\u601d\u8b70\u3002\u3053\u308c\u3060\u3051\u3067\u5f8c\u308d\u306e\u97f3\u304c\u6d88\u3048\u305a\u3001\u540c\u6642\u306b\u518d\u751f\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3068\u3001iOS\u6a19\u6e96\u306e\u97f3\u697d\u30a2\u30d7\u30ea\u304c\u9cf4\u3063\u3066\u3044\u3066\u3082\u97f3\u3092\u540c\u6642\u518d\u751f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\n\t\u306a\u305cAppDelegate\u306b\u3053\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u5165\u308c\u308b\u3068\u540c\u6642\u518d\u751f\u3067\u304d\u308b\u306e\u304b\u3068\u3044\u3046\u3068\u3001\u97f3\u697d\u518d\u751f\u6642\u306b\u306f\u30aa\u30fc\u30c7\u30a3\u30aa\u30bb\u30c3\u30b7\u30e7\u30f3\u30ab\u30c6\u30b4\u30ea\u3068\u3044\u3046\u30a2\u30d7\u30ea\u5185\u5171\u901a\u306e\u97f3\u8a2d\u5b9a\u304c\u3042\u308a\u3001\u6a19\u6e96\u3067\u306f\u5358\u66f2\u518d\u751f\u3059\u308b\u305f\u3081\u3001MPMusicPlayer\u3067\u518d\u751f\u3055\u308c\u305f\u66f2\u3092\u6b62\u3081\u3066\u3057\u307e\u3044\u307e\u3059\u3002\n\t<\/p>\n<\/p>\n<p>\n\t\t\t\u3053\u308c\u3092AppDelegate\u3067\u540c\u6642\u518d\u751f\u53ef\u80fd\u306a\u30ab\u30c6\u30b4\u30ea\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u3001\u30a2\u30d7\u30ea\u5185\u3067\u3044\u3064\u97f3\u3092\u518d\u751f\u3057\u3066\u3082\u3001\u5f8c\u308d\u306e\u97f3\u697d\u3092\u6b62\u3081\u305a\u306b\u518d\u751f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3001\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002\n\t\t<\/p>\n<p>\n\t\t\t\u8a73\u3057\u304f\u306f\u300c<br \/>\n\t\t\tiOS \u30aa\u30fc\u30c7\u30a3\u30aa\u30bb\u30c3\u30b7\u30e7\u30f3\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30ac\u30a4\u30c9(pdf)<br \/>\n\t\t\t\u300d\u306e\u300c\u30ab\u30c6\u30b4\u30ea\u306e\u7a2e\u985e\u300d\u306e\u9805\u76ee\u304c\u53c2\u8003\u306b\u306a\u308a\u307e\u3059\u3002\n\t\t<\/p>\n<p>\n\t\t\t\u4ed6\u306b\u3082\u300c<br \/>\n\t\t\tiPod\u30e9\u30a4\u30d6\u30e9\u30ea\u30a2\u30af\u30bb\u30b9\u30ac\u30a4\u30c9(pdf)<br \/>\n\t\t\t\u300d\u3001\u300c<br \/>\n\t\t\tAV Foundation\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30ac\u30a4\u30c9(pdf)<br \/>\n\t\t\t\u300d\u3082iOS\u3067\u306e\u97f3\u697d\u518d\u751f\u306e\u7406\u89e3\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\n\t\t<\/p>\n<p><\/p>\n<p>\n\t\t\tAVAudioPlayer\u3068MPMusicPlayer\u3067\u97f3\u3092\u540c\u6642\u518d\u751f\u3059\u308b\u306e\u306b\u3053\u3093\u306a\u306b\u60a9\u3080\u3068\u306f\u2026\u3002\n\t\t\t<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS\u3067\u306f\u97f3\u3092\u518d\u751f\u3059\u308b\u6642\u306e\u9078\u629e\u80a2\u3068\u3057\u3066 MediaPlayer Farmework \u3068 AVFoundation Framework\u306e\uff12\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002 \u4eca\u56de\u306f\u3053\u308c\u3089\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u591a\u91cd\u518d\u751f\u304c\u3067\u304d\u306a\u3044\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u3066\u307f\u307e\u3057 &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/ios_play_sounds_and_background_music_simultaneously.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">\u3010iOS\u3011\u97f3\u697d\u3092\u6b62\u3081\u305a\u306b\u52b9\u679c\u97f3\u3092\u540c\u6642\u306b\u518d\u751f\u3059\u308b\u306b\u306f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[119,116,121,120],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-ios-dev","tag-avfoundation","tag-ios","tag-ipod-library","tag-mediaplayer"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":3,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1858,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1086\/revisions\/1858"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}