From 212337c7c158c7778d91c4b8fb98b144b8e111d7 Mon Sep 17 00:00:00 2001 From: pponso1 Date: Sat, 16 Jan 2016 11:57:00 -0600 Subject: [PATCH 1/5] iOS audio support --- gfx/drivers_context/cocoa_gl_ctx.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gfx/drivers_context/cocoa_gl_ctx.m b/gfx/drivers_context/cocoa_gl_ctx.m index afed1a5cb3..1c60c40ad2 100644 --- a/gfx/drivers_context/cocoa_gl_ctx.m +++ b/gfx/drivers_context/cocoa_gl_ctx.m @@ -26,6 +26,7 @@ #include #elif defined(HAVE_COCOATOUCH) #include +#import #endif #include @@ -119,6 +120,10 @@ void *glkitview_init(void) #if defined(HAVE_COCOATOUCH) void cocoagl_bind_game_view_fbo(void) { + // implicitly initializes your audio session + [AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil]; + [audioSession setActive:YES error:nil]; if (g_context) [g_view bindDrawable]; } From 452c6afaf048b6b4f1edcda7874f98f4ea95a3d3 Mon Sep 17 00:00:00 2001 From: pponso1 Date: Sat, 16 Jan 2016 12:09:44 -0600 Subject: [PATCH 2/5] support for playing Music.app in background. --- ui/drivers/cocoa/cocoa_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/drivers/cocoa/cocoa_common.h b/ui/drivers/cocoa/cocoa_common.h index cc0287b78a..84078b49c8 100644 --- a/ui/drivers/cocoa/cocoa_common.h +++ b/ui/drivers/cocoa/cocoa_common.h @@ -74,6 +74,7 @@ extern apple_frontend_settings_t apple_frontend_settings; - (void)showGameView; - (void)toggleUI; +- (void)supportOtherAudioSessions; - (void)refreshSystemConfig; - (void)mainMenuPushPop: (bool)pushp; From 3ce5ad92436ceafa8535873fe8d64f5ed8966a53 Mon Sep 17 00:00:00 2001 From: pponso1 Date: Sat, 16 Jan 2016 12:25:57 -0600 Subject: [PATCH 3/5] iOS. Adding support for Music.app. Users who want to play games while listening to music should enjoy these modifications. Not the cleanest; refactoring is needed. --- ui/drivers/ui_cocoatouch.m | 40 ++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 8c23ac42c7..b6f09c6950 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -27,7 +27,7 @@ #include "../../input/drivers/cocoa_input.h" #include "../../input/drivers_keyboard/keyboard_event_apple.h" #include "../../retroarch.h" - +#import #include "../../frontend/frontend.h" #include "../../runloop.h" @@ -44,6 +44,10 @@ void apple_rarch_exited(void); static void rarch_enable_ui(void) { + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil]; + [audioSession setActive:YES error:nil]; + bool boolean = true; ui_companion_set_foreground(true); @@ -62,6 +66,9 @@ static void rarch_disable_ui(void) runloop_ctl(RUNLOOP_CTL_SET_PAUSED, &boolean); runloop_ctl(RUNLOOP_CTL_SET_IDLE, &boolean); rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil]; + [audioSession setActive:YES error:nil]; } static void ui_companion_cocoatouch_event_command( @@ -314,6 +321,10 @@ enum + (RetroArch_iOS*)get { + // implicitly initializes your audio session + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil]; + [audioSession setActive:YES error:nil]; return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate]; } @@ -325,7 +336,8 @@ enum if (rarch_main(0, NULL, NULL)) apple_rarch_exited(); - + /* Other background audio check */ + [self supportOtherAudioSessions]; /* Setup window */ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window makeKeyAndVisible]; @@ -336,6 +348,7 @@ enum [self refreshSystemConfig]; [self showGameView]; + [self supportOtherAudioSessions]; if (rarch_main(0, NULL, NULL)) apple_rarch_exited(); @@ -352,7 +365,7 @@ enum - (void)applicationDidEnterBackground:(UIApplication *)application { - + [self supportOtherAudioSessions]; } - (void)applicationWillTerminate:(UIApplication *)application @@ -365,7 +378,8 @@ enum - (void)applicationDidBecomeActive:(UIApplication *)application { settings_t *settings = config_get_ptr(); - + + [self supportOtherAudioSessions]; if (settings->ui.companion_start_on_boot) return; @@ -374,6 +388,7 @@ enum - (void)applicationWillResignActive:(UIApplication *)application { + [self supportOtherAudioSessions]; dispatch_async(dispatch_get_main_queue(), ^{ ui_companion_cocoatouch_event_command(NULL, EVENT_CMD_MENU_SAVE_CURRENT_CONFIG); @@ -385,7 +400,8 @@ enum { NSString *filename = (NSString*)url.path.lastPathComponent; NSError *error = nil; - + [self supportOtherAudioSessions]; + [[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error]; if (error) @@ -402,6 +418,8 @@ enum - (void)showGameView { + // implicitly initializes your audio session + [self supportOtherAudioSessions]; [self popToRootViewControllerAnimated:NO]; [self setToolbarHidden:true animated:NO]; [[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationNone]; @@ -414,7 +432,7 @@ enum - (IBAction)showPauseMenu:(id)sender { - ui_companion_cocoatouch_event_command(NULL, EVENT_CMD_AUDIO_STOP); + //ui_companion_cocoatouch_event_command(NULL, EVENT_CMD_AUDIO_STOP); rarch_enable_ui(); [[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationNone]; @@ -433,6 +451,7 @@ enum { [self showPauseMenu:self]; } + [self supportOtherAudioSessions]; } - (void)refreshSystemConfig @@ -471,6 +490,14 @@ enum } } +- (void)supportOtherAudioSessions +{ + // implicitly initializes your audio session + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil]; + [audioSession setActive:YES error:nil]; +} + - (void)mainMenuRenderMessageBox:(NSString *)msg { [self.mainmenu renderMessageBox:msg]; @@ -501,6 +528,7 @@ void apple_rarch_exited(void) if (!ap) return; + [ap supportOtherAudioSessions]; [ap showPauseMenu:ap]; } From a983c8269e342edb8c85b86ea3600680824339b1 Mon Sep 17 00:00:00 2001 From: pponso1 Date: Sat, 16 Jan 2016 12:37:09 -0600 Subject: [PATCH 4/5] iOS. Adding support for Music.app. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I had to comment out this line in the showPauseMenu function: ui_companion_cocoatouch_event_command(NULL, EVENT_CMD_AUDIO_STOP); This may actually be on the only change needed. 😜 --- ui/drivers/ui_cocoatouch.m | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index b6f09c6950..662eb95b78 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -400,7 +400,6 @@ enum { NSString *filename = (NSString*)url.path.lastPathComponent; NSError *error = nil; - [self supportOtherAudioSessions]; [[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error]; From 48b99b1f48b46f60809590780caae3b964549e35 Mon Sep 17 00:00:00 2001 From: Phillip Ponson Date: Sat, 16 Jan 2016 12:48:33 -0600 Subject: [PATCH 5/5] =?UTF-8?q?Fixing=20a=20build=20issue.=20syntax=20erro?= =?UTF-8?q?rs.=20=F0=9F=98=A3=20.=20'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gfx/drivers_context/cocoa_gl_ctx.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/drivers_context/cocoa_gl_ctx.m b/gfx/drivers_context/cocoa_gl_ctx.m index 1c60c40ad2..31524ab97e 100644 --- a/gfx/drivers_context/cocoa_gl_ctx.m +++ b/gfx/drivers_context/cocoa_gl_ctx.m @@ -121,7 +121,7 @@ void *glkitview_init(void) void cocoagl_bind_game_view_fbo(void) { // implicitly initializes your audio session - [AVAudioSession *audioSession = [AVAudioSession sharedInstance]; + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil]; [audioSession setActive:YES error:nil]; if (g_context)