Skip to content

Commit

Permalink
Migrate iOS to swift and AVPlaye (#285)
Browse files Browse the repository at this point in the history
Resolve #284 

Release ASAP as a `beta release`. => `3.0.0-beta.1`

Closes #231 #245 #275
  • Loading branch information
hyochan authored May 8, 2021
1 parent eff8bc1 commit 5b7c9b0
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 370 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## Changelogs
- **[3.0.0-beta.1]**
- [iOS]
* Codebase re-written in `Swift`.
* Migrate `AVAudioPlayer` to `AVPlayer`.
- **[2.7.0]**
- Migrate `android` module to `kotlin`.
- **[2.6.2]**
Expand Down
5 changes: 3 additions & 2 deletions Example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ class Page extends Component<any, State> {
private onStartPlay = async () => {
console.log('onStartPlay');
const msg = await this.audioRecorderPlayer.startPlayer(this.path);
this.audioRecorderPlayer.setVolume(1.0);
console.log(msg);
const volume = await this.audioRecorderPlayer.setVolume(1.0);
console.log(`file: ${msg}`, `volume: ${volume}`);

this.audioRecorderPlayer.addPlayBackListener((e: any) => {
if (e.current_position === e.duration) {
console.log('finished');
Expand Down
1 change: 1 addition & 0 deletions Example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target 'RNAudioRecorderPlayer' do
# you should disable the next line.
use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })


post_install do |installer|
react_native_post_install(installer)
end
Expand Down
4 changes: 2 additions & 2 deletions Example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,10 @@ SPEC CHECKSUMS:
React-runtimeexecutor: cad74a1eaa53ee6e7a3620231939d8fe2c6afcf0
ReactCommon: cfe2b7fd20e0dbd2d1185cd7d8f99633fbc5ff05
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
RNAudioRecorderPlayer: afbacfc9312e836a4299407b896d42cf3bab6c3a
RNAudioRecorderPlayer: 415f616f2db152d9e6e11011fd8b192d3ef6606d
Yoga: 8c8436d4171c87504c648ae23b1d81242bdf3bbf
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 1764a8118c59a5127e35c36ef37ef22f785b1a62
PODFILE CHECKSUM: 6398d8875e876b57a0b08c900810453dfb882c9c

COCOAPODS: 1.10.1
9 changes: 7 additions & 2 deletions Example/ios/RNAudioRecorderPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
00E356F31AD99517003FC87E /* RNAudioRecorderPlayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* RNAudioRecorderPlayerTests.m */; };
0E7EAFD72642888200F4C51F /* SwiftBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7EAFD62642888200F4C51F /* SwiftBridge.swift */; };
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
Expand All @@ -31,6 +32,7 @@
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* RNAudioRecorderPlayerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNAudioRecorderPlayerTests.m; sourceTree = "<group>"; };
0B595183C5E56B684890DD40 /* Pods-RNAudioRecorderPlayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNAudioRecorderPlayer.debug.xcconfig"; path = "Target Support Files/Pods-RNAudioRecorderPlayer/Pods-RNAudioRecorderPlayer.debug.xcconfig"; sourceTree = "<group>"; };
0E7EAFD62642888200F4C51F /* SwiftBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftBridge.swift; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* RNAudioRecorderPlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RNAudioRecorderPlayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = RNAudioRecorderPlayer/AppDelegate.h; sourceTree = "<group>"; };
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = RNAudioRecorderPlayer/AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -116,6 +118,7 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
0E7EAFD62642888200F4C51F /* SwiftBridge.swift */,
13B07FAE1A68108700A75B9A /* RNAudioRecorderPlayer */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* RNAudioRecorderPlayerTests */,
Expand Down Expand Up @@ -145,7 +148,6 @@
B1F18E999E49CF88AAD205B3 /* Pods-RNAudioRecorderPlayer-RNAudioRecorderPlayerTests.debug.xcconfig */,
DE6831B173502234E195B22A /* Pods-RNAudioRecorderPlayer-RNAudioRecorderPlayerTests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -208,7 +210,7 @@
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
LastSwiftMigration = 1120;
LastSwiftMigration = 1250;
};
};
};
Expand Down Expand Up @@ -413,6 +415,7 @@
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
0E7EAFD72642888200F4C51F /* SwiftBridge.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -431,6 +434,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = B1F18E999E49CF88AAD205B3 /* Pods-RNAudioRecorderPlayer-RNAudioRecorderPlayerTests.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -458,6 +462,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = DE6831B173502234E195B22A /* Pods-RNAudioRecorderPlayer-RNAudioRecorderPlayerTests.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = RNAudioRecorderPlayerTests/Info.plist;
Expand Down
2 changes: 2 additions & 0 deletions Example/ios/RNAudioRecorderPlayer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSMicrophoneUsageDescription</key>
<string>Give $(PRODUCT_NAME) permission to use your microphone. Your record wont be shared without your permission.</string>
</dict>
</plist>
8 changes: 8 additions & 0 deletions Example/ios/SwiftBridge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// SwiftBridge.swift
// RNAudioRecorderPlayer
//
// Created by hyochan on 2021/05/05.
//

import Foundation
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ This is a react-native link module for audio recorder and player. This is not a

## Breaking Changes

- From version `3.0.+`, a critical migration has been done. Current version is not much different from version `2.0.+` in usability, but there are many changes internally.
1. Codebase has been re-written to [kotlin for Android](https://kotlinlang.org) and [swift for iOS](https://swift.org).
[iOS]
* [AVAudioPlayer](https://developer.apple.com/documentation/avfaudio/avaudioplayer) has been migrated to [AVPlayer](https://developer.apple.com/documentation/avfoundation/avplayer) which supports stream and more possibilities [#231](https://github.com/hyochan/react-native-audio-recorder-player/issues/231), [#245](https://github.com/hyochan/react-native-audio-recorder-player/issues/245), [#275](https://github.com/hyochan/react-native-audio-recorder-player/issues/275).

- There has been vast improvements in [#114](https://github.com/dooboolab/react-native-audio-recorder-player/pull/114) which is released in `2.3.0`. We now support all `RN` versions without any version differenciating. See below installation guide for your understanding.

## Migration Guide
Expand All @@ -34,6 +39,7 @@ This is a react-native link module for audio recorder and player. This is not a
| `resume` | `resumePlayer` |
| `seekTo` | `seekToPlayer` |
| | `setSubscriptionDuration` |
| `addPlayBackListener` | `addPlayBackListener` |
| `setRecordInterval` | `addRecordBackListener` |
| `removeRecordInterval` | `` |
| | `setVolume` |
Expand Down Expand Up @@ -81,15 +87,24 @@ npx pod-install
compile project(':react-native-audio-recorder-player')
```

### Post installation
## Post installation

#### iOS

On _iOS_ you need to add a usage description to `Info.plist`:

```xml
<key>NSMicrophoneUsageDescription</key>
<string>This sample uses the microphone to record your speech and convert it to text.</string>
<string>Give $(PRODUCT_NAME) permission to use your microphone. Your record wont be shared without your permission.</string>
```

Also, add [swift bridging header](https://stackoverflow.com/questions/31716413/xcode-not-automatically-creating-bridging-header) if you haven't created one for `swift` compatibility.

<img width="800" alt="1" src="https://user-images.githubusercontent.com/27461460/111863065-8be6e300-899c-11eb-8ad8-6811e0bd0fbd.png">


#### Android

On _Android_ you need to add a permission to `AndroidManifest.xml`:

```xml
Expand Down Expand Up @@ -173,7 +188,7 @@ All methods are implemented with promises.
| seekToPlayer | `number` miliseconds | `Promise<string>` | Seek audio. |
| setVolume | `doulbe` value | `Promise<string>` | Set volume of audio player (default 1.0, range: 0.0 ~ 1.0). |

## Customizing recorded audio quality (from `2.3.0`)
## Able to customize recorded audio quality (from `2.3.0`)

```
interface AudioSet {
Expand Down
6 changes: 3 additions & 3 deletions RNAudioRecorderPlayer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Pod::Spec.new do |s|

s.authors = package['author']
s.homepage = package['homepage']
s.platform = :ios, "9.0"
s.platform = :ios, "11.0"

s.source = { :git => "https://github.com/dooboolab/react-native-audio-recorder-player.git", :tag => "#{s.version}" }
s.source_files = "ios/**/*.{h,m}"
s.source = { :git => "https://github.com/hyochan/react-native-audio-recorder-player.git", :tag => "#{s.version}" }
s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"

s.dependency 'React'
end
Expand Down
2 changes: 0 additions & 2 deletions ios/RNAudioRecorderPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
successfully:(BOOL)flag;
- (void)updateRecorderProgress:(NSTimer*) timer;
- (void)updateProgress:(NSTimer*) timer;
- (void)startRecorderTimer;
- (void)startPlayerTimer;
@end
Loading

0 comments on commit 5b7c9b0

Please sign in to comment.