[ https://issues.apache.org/jira/browse/CB-7684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16317073#comment-16317073 ]
ASF GitHub Bot commented on CB-7684: ------------------------------------ macdonst closed pull request #143: CB-7684 URL: https://github.com/apache/cordova-plugin-media/pull/143 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/plugin.xml b/plugin.xml index dabafac7..564f6da3 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,7 @@ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-media" - version="3.0.1"> + version="5.0.2-dev"> <name>Media</name> <description>Cordova Media Plugin</description> @@ -31,11 +31,10 @@ id="cordova-plugin-media" <issue>https://issues.apache.org/jira/browse/CB/component/12320647</issue> <engines> - <engine name="cordova-android" version=">=6.1.0" /> + <engine name="cordova-android" version=">=6.3.0" /> </engines> - <dependency id="cordova-plugin-file" version="^4.0.0" /> - <dependency id="cordova-plugin-compat" version="^1.0.0" /> + <dependency id="cordova-plugin-file" version="^6.0.0" /> <js-module src="www/MediaError.js" name="MediaError"> <clobbers target="window.MediaError" /> @@ -65,106 +64,19 @@ id="cordova-plugin-media" <source-file src="src/android/FileHelper.java" target-dir="src/org/apache/cordova/media" /> </platform> - <!-- amazon-fireos --> - <platform name="amazon-fireos"> - <config-file target="res/xml/config.xml" parent="/*"> - <feature name="Media" > - <param name="android-package" value="org.apache.cordova.media.AudioHandler"/> - </feature> - </config-file> - - <config-file target="AndroidManifest.xml" parent="/*"> - <uses-permission android:name="android.permission.RECORD_AUDIO" /> - <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.READ_PHONE_STATE" /> - </config-file> - - <source-file src="src/android/AudioHandler.java" target-dir="src/org/apache/cordova/media" /> - <source-file src="src/android/AudioPlayer.java" target-dir="src/org/apache/cordova/media" /> - <source-file src="src/android/FileHelper.java" target-dir="src/org/apache/cordova/media" /> - </platform> - - - <!-- ubuntu --> - <platform name="ubuntu"> - <config-file target="config.xml" parent="/*"> - <feature name="Media"> - <param policy_group="microphone" policy_version="1" /> - <param policy_group="video" policy_version="1" /> - </feature> - </config-file> - <header-file src="src/ubuntu/media.h" /> - <source-file src="src/ubuntu/media.cpp" /> - </platform> - <!-- ios --> <platform name="ios"> + <preference name="KEEP_AVAUDIOSESSION_ALWAYS_ACTIVE" default="NO" /> <config-file target="config.xml" parent="/*"> <feature name="Media"> <param name="ios-package" value="CDVSound" /> </feature> + <preference + name="KeepAVAudioSessionAlwaysActive" + value="$KEEP_AVAUDIOSESSION_ALWAYS_ACTIVE" /> </config-file> <header-file src="src/ios/CDVSound.h" /> <source-file src="src/ios/CDVSound.m" /> - <preference name="MICROPHONE_USAGE_DESCRIPTION" default=" " /> - <config-file target="*-Info.plist" parent="NSMicrophoneUsageDescription"> - <string>$MICROPHONE_USAGE_DESCRIPTION</string> - </config-file> - </platform> - - <!-- blackberry10 --> - <platform name="blackberry10"> - <source-file src="src/blackberry10/index.js" target-dir="Media" /> - <config-file target="www/config.xml" parent="/widget"> - <feature name="Media" value="Media"/> - </config-file> - </platform> - - <!-- wp7 --> - <platform name="wp7"> - <config-file target="config.xml" parent="/*"> - <feature name="Media"> - <param name="wp-package" value="Media"/> - </feature> - </config-file> - - <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> - <Capability Name="ID_CAP_MEDIALIB"/> - <Capability Name="ID_CAP_MICROPHONE"/> - </config-file> - - <source-file src="src/wp/Media.cs" /> - <source-file src="src/wp/AudioPlayer.cs" /> - </platform> - - <!-- wp8 --> - <platform name="wp8"> - <config-file target="config.xml" parent="/*"> - <feature name="Media"> - <param name="wp-package" value="Media"/> - </feature> - </config-file> - - <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities"> - <Capability Name="ID_CAP_MEDIALIB_AUDIO"/> - <Capability Name="ID_CAP_MEDIALIB_PLAYBACK"/> - <Capability Name="ID_CAP_MICROPHONE"/> - </config-file> - - <source-file src="src/wp/Media.cs" /> - <source-file src="src/wp/AudioPlayer.cs" /> - </platform> - - <!-- windows8 --> - <platform name="windows8"> - <js-module src="src/windows/MediaProxy.js" name="MediaProxy"> - <runs /> - </js-module> - - <config-file target="package.appxmanifest" parent="/Package/Capabilities"> - <DeviceCapability Name="microphone" /> - </config-file> </platform> <!-- windows --> @@ -178,13 +90,6 @@ id="cordova-plugin-media" </config-file> </platform> - <!-- tizen --> - <platform name="tizen"> - <js-module src="src/tizen/MediaProxy.js" name="MediaProxy"> - <runs/> - </js-module> - </platform> - <!-- browser --> <platform name="browser"> <js-module src="www/browser/Media.js" name="BrowserMedia"> diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m index e1542871..e8947d0f 100644 --- a/src/ios/CDVSound.m +++ b/src/ios/CDVSound.m @@ -27,8 +27,24 @@ Licensed to the Apache Software Foundation (ASF) under one @implementation CDVSound +BOOL keepAvAudioSessionAlwaysActive = NO; + @synthesize soundCache, avSession, currMediaId, statusCallbackId; +-(void) pluginInitialize +{ + NSDictionary* settings = self.commandDelegate.settings; + keepAvAudioSessionAlwaysActive = [[settings objectForKey:[@"KeepAVAudioSessionAlwaysActive" lowercaseString]] boolValue]; + if (keepAvAudioSessionAlwaysActive) { + if ([self hasAudioSession]) { + NSError* error = nil; + if(![self.avSession setActive:YES error:&error]) { + NSLog(@"Unable to activate session: %@", [error localizedFailureReason]); + } + } + } +} + // Maps a url for a resource path for recording - (NSURL*)urlForRecording:(NSString*)resourcePath { @@ -421,7 +437,7 @@ - (void)startPlayingAudio:(CDVInvokedUrlCommand*)command [audioFile.player play]; } */ // error creating the session or player - [self onStatus:MEDIA_ERROR mediaId:mediaId + [self onStatus:MEDIA_ERROR mediaId:mediaId param:[self createMediaErrorWithCode:MEDIA_ERR_NONE_SUPPORTED message:nil]]; } } @@ -469,7 +485,7 @@ - (BOOL)prepareToPlay:(CDVAudioFile*)audioFile withId:(NSString*)mediaId if (playerError != nil) { NSLog(@"Failed to initialize AVAudioPlayer: %@\n", [playerError localizedDescription]); audioFile.player = nil; - if (self.avSession) { + if (! keepAvAudioSessionAlwaysActive && self.avSession && ! [self isPlayingOrRecording]) { [self.avSession setActive:NO error:nil]; } bError = YES; @@ -600,7 +616,7 @@ - (void)release:(CDVInvokedUrlCommand*)command [avPlayer pause]; avPlayer = nil; } - if (self.avSession) { + if (! keepAvAudioSessionAlwaysActive && self.avSession && ! [self isPlayingOrRecording]) { [self.avSession setActive:NO error:nil]; self.avSession = nil; } @@ -705,7 +721,7 @@ - (void)startRecordingAudio:(CDVInvokedUrlCommand*)command errorMsg = @"Failed to start recording using AVAudioRecorder"; } audioFile.recorder = nil; - if (weakSelf.avSession) { + if (! keepAvAudioSessionAlwaysActive && weakSelf.avSession && ! [self isPlayingOrRecording]) { [weakSelf.avSession setActive:NO error:nil]; } [weakSelf onStatus:MEDIA_ERROR mediaId:mediaId param: @@ -725,7 +741,7 @@ - (void)startRecordingAudio:(CDVInvokedUrlCommand*)command NSString* msg = @"Error creating audio session, microphone permission denied."; NSLog(@"%@", msg); audioFile.recorder = nil; - if (weakSelf.avSession) { + if (! keepAvAudioSessionAlwaysActive && weakSelf.avSession && ! [self isPlayingOrRecording]) { [weakSelf.avSession setActive:NO error:nil]; } [weakSelf onStatus:MEDIA_ERROR mediaId:mediaId param: @@ -773,7 +789,7 @@ - (void)audioRecorderDidFinishRecording:(AVAudioRecorder*)recorder successfully: [self onStatus:MEDIA_ERROR mediaId:mediaId param: [self createMediaErrorWithCode:MEDIA_ERR_DECODE message:nil]]; } - if (self.avSession) { + if (! keepAvAudioSessionAlwaysActive && self.avSession && ! [self isPlayingOrRecording]) { [self.avSession setActive:NO error:nil]; } } @@ -795,18 +811,18 @@ - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer*)player successfully:(BOOL)fl [self onStatus:MEDIA_ERROR mediaId:mediaId param: [self createMediaErrorWithCode:MEDIA_ERR_DECODE message:nil]]; } - if (self.avSession) { - [self.avSession setActive:NO error:nil]; - } + if (! keepAvAudioSessionAlwaysActive && self.avSession && ! [self isPlayingOrRecording]) { + [self.avSession setActive:NO error:nil]; + } } -(void)itemDidFinishPlaying:(NSNotification *) notification { // Will be called when AVPlayer finishes playing playerItem NSString* mediaId = self.currMediaId; - if (self.avSession) { - [self.avSession setActive:NO error:nil]; - } + if (! keepAvAudioSessionAlwaysActive && self.avSession && ! [self isPlayingOrRecording]) { + [self.avSession setActive:NO error:nil]; + } [self onStatus:MEDIA_STATE mediaId:mediaId param:@(MEDIA_STOPPED)]; } @@ -917,7 +933,7 @@ - (void)onStatus:(CDVMediaMsg)what mediaId:(NSString*)mediaId param:(NSObject*)p status[@"msgType"] = @(what); //in the error case contains a dict with "code" and "message" //otherwise a NSNumber - status[@"value"] = param; + status[@"value"] = param; status[@"id"] = mediaId; NSMutableDictionary* dict=[NSMutableDictionary dictionary]; dict[@"action"] = @"status"; @@ -931,12 +947,26 @@ - (void)onStatus:(CDVMediaMsg)what mediaId:(NSString*)mediaId param:(NSObject*)p param=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; } NSString* jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", - @"cordova.require('cordova-plugin-media.Media').onStatus", + @"cordova.require('cordova-plugin-media.Media').onStatus", mediaId, (int)what, param]; [self.commandDelegate evalJs:jsString]; } } +-(BOOL) isPlayingOrRecording +{ + for(NSString* mediaId in soundCache) { + CDVAudioFile* audioFile = [soundCache objectForKey:mediaId]; + if (audioFile.player && [audioFile.player isPlaying]) { + return true; + } + if (audioFile.recorder && [audioFile.recorder isRecording]) { + return true; + } + } + return false; +} + @end @implementation CDVAudioFile ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [Media] CDVSound Kills any and all playing sound files when a single file > finishes > ---------------------------------------------------------------------------------- > > Key: CB-7684 > URL: https://issues.apache.org/jira/browse/CB-7684 > Project: Apache Cordova > Issue Type: Sub-task > Components: cordova-plugin-media > Affects Versions: 3.5.0 > Environment: iOS > Reporter: Nathan Stryker > > The CDVSound file will kill all playing media files when ever a single file > completes playing. The issue is around like 691 in the method > "AudioDidFinishPlaying", with the code: > if (self.avSession) { > [self.avSession setActive:NO error:nil]; > } > The reason I think this is a bug is that if a user as Music file A playing in > a loop and Music file B plays, when B completes the "setActive:NO" will kill > the avSession of both A and B. -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org