Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24448] iOS: Decouple Ti.Media music-API macros #8857

Merged
merged 2 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions iphone/Classes/MediaModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#import "KrollCallback.h"
#import "TiMediaAudioSession.h"
#import "MediaPlayer/MediaPlayer.h"
#if defined(USE_TI_MEDIASYSTEMMUSICPLAYER) || defined (USE_TI_MEDIAAPPMUSICPLAYER)
#import "TiMediaMusicPlayer.h"
#endif
#import "TiViewProxy.h"

@interface MediaModule : TiModule
Expand Down Expand Up @@ -44,10 +42,8 @@
#endif

// Music players
#if defined(USE_TI_MEDIASYSTEMMUSICPLAYER) || defined (USE_TI_MEDIAAPPMUSICPLAYER)
TiMediaMusicPlayer* systemMusicPlayer;
TiMediaMusicPlayer* appMusicPlayer;
#endif

// Shared picker bits; OK, since they're modal (and we can perform sanity checks for the necessary bits)
BOOL animatedPicker;
Expand Down Expand Up @@ -80,10 +76,9 @@
@property(nonatomic,readonly) NSNumber* cameraAuthorizationStatus;
@property(nonatomic, assign) NSNumber* audioSessionMode;
@property(nonatomic, assign) NSString* audioSessionCategory;
#ifdef USE_TI_MEDIAMUSICPLAYER

@property(nonatomic,readonly) TiMediaMusicPlayer* systemMusicPlayer;
@property(nonatomic,readonly) TiMediaMusicPlayer* appMusicPlayer;
#endif

@property(nonatomic,readonly) NSNumber* UNKNOWN_ERROR;
@property(nonatomic,readonly) NSNumber* DEVICE_BUSY;
Expand Down
36 changes: 1 addition & 35 deletions iphone/Classes/MediaModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#import "Ti2DMatrix.h"
#import "SCListener.h"
#import "TiMediaAudioSession.h"
#ifdef USE_TI_MEDIAMUSICPLAYER
#import "TiMediaMusicPlayer.h"
#endif
#import "TiMediaItem.h"

#import <AudioToolbox/AudioToolbox.h>
Expand Down Expand Up @@ -123,10 +121,8 @@ @implementation MediaModule
-(void)dealloc
{
[self destroyPicker];
#if defined(USE_TI_MEDIASYSTEMMUSICPLAYER) || defined (USE_TI_MEDIAAPPMUSICPLAYER)
RELEASE_TO_NIL(systemMusicPlayer);
RELEASE_TO_NIL(appMusicPlayer);
#endif
RELEASE_TO_NIL(popoverView);
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
Expand Down Expand Up @@ -209,7 +205,6 @@ -(NSString*)apiName
#endif

//Constants for currentRoute
#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
MAKE_SYSTEM_STR(AUDIO_SESSION_PORT_LINEIN,AVAudioSessionPortLineIn)
MAKE_SYSTEM_STR(AUDIO_SESSION_PORT_BUILTINMIC,AVAudioSessionPortBuiltInMic)
MAKE_SYSTEM_STR(AUDIO_SESSION_PORT_HEADSETMIC,AVAudioSessionPortHeadsetMic)
Expand All @@ -234,7 +229,6 @@ -(NSString*)apiName

MAKE_SYSTEM_UINT(AUDIO_SESSION_OVERRIDE_ROUTE_NONE, AVAudioSessionPortOverrideNone);
MAKE_SYSTEM_UINT(AUDIO_SESSION_OVERRIDE_ROUTE_SPEAKER, AVAudioSessionPortOverrideSpeaker);
#endif

//Constants for Camera
#if defined(USE_TI_MEDIACAMERA_FRONT) || defined(USE_TI_MEDIACAMERA_REAR) || defined(USE_TI_MEDIACAMERA_FLASH_OFF) || defined(USE_TI_MEDIACAMERA_FLASH_AUTO) || defined(USE_TI_MEDIACAMERA_FLASH_ON)
Expand Down Expand Up @@ -269,7 +263,6 @@ -(NSNumber*)MUSIC_MEDIA_TYPE_ALL
#endif

//Constants for MusicPlayer playback state
#ifdef USE_TI_MEDIAMUSICPLAYER
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_STOPPED, MPMusicPlaybackStateStopped);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_PLAYING, MPMusicPlaybackStatePlaying);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_STATE_PAUSED, MPMusicPlaybackStatePaused);
Expand All @@ -288,7 +281,6 @@ -(NSNumber*)MUSIC_MEDIA_TYPE_ALL
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_NONE, MPMusicShuffleModeOff);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_SONGS, MPMusicShuffleModeSongs);
MAKE_SYSTEM_PROP(MUSIC_PLAYER_SHUFFLE_ALBUMS, MPMusicShuffleModeAlbums);
#endif

//Error constants for MediaModule
MAKE_SYSTEM_PROP(UNKNOWN_ERROR,MediaModuleErrorUnknown);
Expand Down Expand Up @@ -376,7 +368,6 @@ -(NSNumber*)VIDEO_CONTROL_HIDDEN
MAKE_SYSTEM_PROP(VIDEO_TIME_OPTION_EXACT,MPMovieTimeOptionExact);
#endif

#if defined(USE_TI_MEDIASYSTEMMUSICPLAYER) || defined (USE_TI_MEDIAAPPMUSICPLAYER)
-(TiMediaMusicPlayer*)systemMusicPlayer
{
if (systemMusicPlayer == nil) {
Expand All @@ -385,11 +376,7 @@ -(TiMediaMusicPlayer*)systemMusicPlayer
TiThreadPerformOnMainThread(^{result = [self systemMusicPlayer];}, YES);
return result;
}
if ([TiUtils isIOS8OrGreater]) {
systemMusicPlayer = [[TiMediaMusicPlayer alloc] _initWithPageContext:[self pageContext] player:[MPMusicPlayerController systemMusicPlayer]];
} else {
systemMusicPlayer = [[TiMediaMusicPlayer alloc] _initWithPageContext:[self pageContext] player:[MPMusicPlayerController iPodMusicPlayer]];
}
systemMusicPlayer = [[TiMediaMusicPlayer alloc] _initWithPageContext:[self pageContext] player:[MPMusicPlayerController systemMusicPlayer]];
}
return systemMusicPlayer;
}
Expand All @@ -406,7 +393,6 @@ -(TiMediaMusicPlayer*)appMusicPlayer
}
return appMusicPlayer;
}
#endif

-(void)setDefaultAudioSessionMode:(NSNumber*)mode
{
Expand Down Expand Up @@ -446,7 +432,6 @@ -(void)setAudioSessionMode:(NSNumber*)mode

}

#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
-(void)setAudioSessionCategory:(NSString*)mode
{
[[TiMediaAudioSession sharedSession] setSessionMode:mode];
Expand All @@ -456,7 +441,6 @@ -(NSString*)audioSessionCategory
{
return [[TiMediaAudioSession sharedSession] sessionMode];
}
#endif

#if defined(USE_TI_MEDIAAVAILABLECAMERAMEDIATYPES) || defined(USE_TI_MEDIAISMEDIATYPESUPPORTED)
-(NSArray*)availableCameraMediaTypes
Expand Down Expand Up @@ -521,12 +505,10 @@ -(void)setCameraFlashMode:(id)args
}
#endif

#ifdef USE_TI_MEDIACANRECORD
-(NSNumber*)canRecord
{
return NUMBOOL([[TiMediaAudioSession sharedSession] hasInput]);
}
#endif

#ifdef USE_TI_MEDIAISCAMERASUPPORTED
-(NSNumber*)isCameraSupported
Expand All @@ -551,51 +533,39 @@ -(NSNumber*)cameraAuthorization
}
#endif

#ifdef USE_TI_MEDIAVOLUME
-(NSNumber*)volume
{
return NUMFLOAT([[TiMediaAudioSession sharedSession] volume]);
}
#endif

#ifdef USE_TI_MEDIAAUDIOPLAYING
-(NSNumber*)audioPlaying
{
return NUMBOOL([[TiMediaAudioSession sharedSession] isAudioPlaying]);
}
#endif

#ifdef USE_TI_MEDIACURRENTROUTE
-(NSDictionary*)currentRoute
{
return [[TiMediaAudioSession sharedSession] currentRoute];
}
#endif

#pragma mark Public Methods

#ifdef USE_TI_MEDIABEEP
-(void)beep:(id)unused
{
ENSURE_UI_THREAD(beep,unused);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
#endif

#ifdef USE_TI_MEDIAVIBRATE
-(void)vibrate:(id)args
{
//No pattern support on iOS
[self beep:nil];
}
#endif

#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
-(void)setOverrideAudioRoute:(NSNumber*)mode
{
[[TiMediaAudioSession sharedSession] setRouteOverride:[mode unsignedIntValue]];
}
#endif

/**
Microphone And Recording Support. These make no sense here and should be moved to Audiorecorder
Expand Down Expand Up @@ -2226,7 +2196,6 @@ -(void)audioVolumeChanged:(NSNotification*)note

-(void)_listenerAdded:(NSString *)type count:(int)count
{
#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
if (count == 1 && [type isEqualToString:@"routechange"])
{
WARN_IF_BACKGROUND_THREAD_OBJ; //NSNotificationCenter is not threadsafe
Expand All @@ -2247,12 +2216,10 @@ -(void)_listenerAdded:(NSString *)type count:(int)count
{
DebugLog(@"[WARN] This event is no longer supported by the MediaModule. Listen for the routechange event instead");
}
#endif
}

-(void)_listenerRemoved:(NSString *)type count:(int)count
{
#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
if (count == 0 && [type isEqualToString:@"routechange"])
{
WARN_IF_BACKGROUND_THREAD_OBJ; //NSNotificationCenter is not threadsafe!
Expand All @@ -2265,7 +2232,6 @@ -(void)_listenerRemoved:(NSString *)type count:(int)count
[[TiMediaAudioSession sharedSession] stopAudioSession];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiMediaAudioSessionVolumeChange object:[TiMediaAudioSession sharedSession]];
}
#endif
}

@end
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiMediaAudioSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
#ifdef USE_TI_MEDIA

extern NSString * const kTiMediaAudioSessionInterruptionBegin;
extern NSString * const kTiMediaAudioSessionInterruptionEnd;
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiMediaAudioSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_MEDIAAUDIOPLAYER) || defined(USE_TI_MEDIAMUSICPLAYER) || defined(USE_TI_MEDIASOUND) || defined (USE_TI_MEDIAVIDEOPLAYER) || defined(USE_TI_MEDIAAUDIORECORDER)
#ifdef USE_TI_MEDIA

#import "TiMediaAudioSession.h"
#import "TiUtils.h"
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiMediaItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_MEDIAQUERYMUSICLIBRARY) || defined(USE_TI_MEDIAOPENMUSICLIBRARY) || defined(USE_TI_MEDIAMUSICPLAYER)
#ifdef USE_TI_MEDIA

#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiMediaItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_MEDIAQUERYMUSICLIBRARY) || defined(USE_TI_MEDIAOPENMUSICLIBRARY) || defined(USE_TI_MEDIAMUSICPLAYER)
#ifdef USE_TI_MEDIA

#import "TiMediaItem.h"
#import "MediaModule.h"


@implementation TiMediaItem

#pragma mark Internal
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiMediaMusicPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_MEDIASYSTEMMUSICPLAYER) || defined (USE_TI_MEDIAAPPMUSICPLAYER)
#ifdef USE_TI_MEDIA

#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
Expand Down Expand Up @@ -39,5 +39,4 @@
@property(nonatomic,readonly) TiMediaItem* nowPlaying;

@end

#endif
4 changes: 3 additions & 1 deletion iphone/Classes/TiMediaMusicPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#if defined(USE_TI_MEDIASYSTEMMUSICPLAYER) || defined (USE_TI_MEDIAAPPMUSICPLAYER)
#ifdef USE_TI_MEDIA

#import "TiMediaMusicPlayer.h"
#import "MediaModule.h"

Expand Down Expand Up @@ -264,4 +265,5 @@ -(void)volumeDidChange:(NSNotification*)note
}

@end

#endif
2 changes: 0 additions & 2 deletions iphone/Classes/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@
#define USE_TI_MEDIASAVETOPHOTOGALLERY
#define USE_TI_MEDIASTARTVIDEOEDITING
#define USE_TI_MEDIASTOPVIDEOEDITING
#define USE_TI_MEDIASYSTEMMUSICPLAYER
#define USE_TI_MEDIAAPPMUSICPLAYER
#define USE_TI_MEDIAAUDIOPLAYER
#define USE_TI_MEDIAAUDIORECORDER
#define USE_TI_MEDIAMUSICPLAYER
Expand Down