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

Feature/waveform #45

Merged
merged 11 commits into from
Nov 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ ext {
}

android {
packagingOptions { pickFirst '**/*.so' }
ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion
Expand Down Expand Up @@ -197,6 +198,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.github.lincollincol:amplituda:2.1.2'

implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/java/com/ethora/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.ethora.WaveformPackage;


public class MainApplication extends Application implements ReactApplication {

Expand All @@ -27,6 +29,7 @@ protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new WaveformPackage());
return packages;
}

Expand Down
48 changes: 48 additions & 0 deletions android/app/src/main/java/com/ethora/Waveform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.ethora;

import android.content.Context;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;


import linc.com.amplituda.Amplituda;
import linc.com.amplituda.AmplitudaResult;
import linc.com.amplituda.exceptions.io.AmplitudaIOException;


public class Waveform extends ReactContextBaseJavaModule {
Waveform(ReactApplicationContext context) {
super(context);
}
public String result;
public void processAudio(String filePath) {
Context mContext=getReactApplicationContext();
Amplituda amplituda = new Amplituda(mContext);

amplituda.processAudio(filePath).get(result -> getAmpResult(result), exception -> {
if(exception instanceof AmplitudaIOException) {
System.out.println("IO Exception!");
}
});
}
public void getAmpResult(AmplitudaResult<?> input) {
result = input.amplitudesAsJson();
}
@Override
public String getName() {
return "Waveform";
}
@ReactMethod
public void getWaveformArray(String filePath, Promise promise ) {
this.processAudio(filePath);
try{
promise.resolve(this.result);
}catch (Exception e){
promise.reject("Create Event Error", e);
}
}
}
33 changes: 33 additions & 0 deletions android/app/src/main/java/com/ethora/WaveformPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ethora;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class WaveformPackage implements ReactPackage {

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
//We import the module file here
modules.add(new Waveform(reactContext));

return modules;
}

// Backward compatibility
public List<Class<? extends JavaScriptModule>> createJSModules() {
return new ArrayList<>();
}
}
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
minSdkVersion = 24
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "20.1.5948944"
googlePlayServicesAuthVersion = "16.0.1"
reactNativeFFmpegPackage = "audio"
// kotlinVersion = "1.1.16"
}
repositories {
Expand All @@ -28,6 +29,7 @@ allprojects {
repositories {
mavenLocal()
maven {
// url 'https://jitpack.io'
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
Expand All @@ -38,6 +40,6 @@ allprojects {

google()
jcenter()
maven { url 'https://www.jitpack.io' }
maven { url 'https://www.jitpack.io' }
}
}
15 changes: 15 additions & 0 deletions ios/Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Header.h
// ethora
//
// Created by Михайло Могилюк on 16.11.2021.
//

#ifndef Header_h
#define Header_h


#endif /* Header_h */
#import "React/RCTBridgeModule.h
#import "RCTEventDispatcher.h"
#import "RCTEventEmitter.h"
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'
platform :ios, '13.0'

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
Expand Down
21 changes: 14 additions & 7 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ PODS:
- libwebp/mux (1.2.1):
- libwebp/demux
- libwebp/webp (1.2.1)
- mobile-ffmpeg-https (4.4)
- nanopb (2.30908.0):
- nanopb/decode (= 2.30908.0)
- nanopb/encode (= 2.30908.0)
Expand Down Expand Up @@ -423,6 +424,12 @@ PODS:
- react-native-fbsdk-next/Share (4.6.0):
- FBSDKShareKit (~> 9.3)
- React-Core
- react-native-ffmpeg (0.5.2):
- React
- react-native-ffmpeg/https (= 0.5.2)
- react-native-ffmpeg/https (0.5.2):
- mobile-ffmpeg-https (= 4.4)
- React
- react-native-get-random-values (1.7.0):
- React-Core
- react-native-image-picker (3.8.1):
Expand Down Expand Up @@ -528,8 +535,6 @@ PODS:
- React-Core
- RNCMaskedView (0.1.11):
- React
- RNCPicker (2.2.0):
- React-Core
- RNCPushNotificationIOS (1.10.1):
- React-Core
- RNFastImage (8.5.11):
Expand Down Expand Up @@ -656,6 +661,7 @@ DEPENDENCIES:
- react-native-camera (from `../node_modules/react-native-camera`)
- react-native-document-picker (from `../node_modules/react-native-document-picker`)
- react-native-fbsdk-next (from `../node_modules/react-native-fbsdk-next`)
- react-native-ffmpeg (from `../node_modules/react-native-ffmpeg`)
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
- react-native-image-picker (from `../node_modules/react-native-image-picker`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
Expand Down Expand Up @@ -686,7 +692,6 @@ DEPENDENCIES:
- "RNCCheckbox (from `../node_modules/@react-native-community/checkbox`)"
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- "RNCPicker (from `../node_modules/@react-native-picker/picker`)"
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
- RNFastImage (from `../node_modules/react-native-fast-image`)
- "RNFBAnalytics (from `../node_modules/@react-native-firebase/analytics`)"
Expand Down Expand Up @@ -735,6 +740,7 @@ SPEC REPOS:
- GTMSessionFetcher
- libevent
- libwebp
- mobile-ffmpeg-https
- nanopb
- OpenSSL-Universal
- PromisesObjC
Expand Down Expand Up @@ -787,6 +793,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-document-picker"
react-native-fbsdk-next:
:path: "../node_modules/react-native-fbsdk-next"
react-native-ffmpeg:
:path: "../node_modules/react-native-ffmpeg"
react-native-get-random-values:
:path: "../node_modules/react-native-get-random-values"
react-native-image-picker:
Expand Down Expand Up @@ -847,8 +855,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-clipboard/clipboard"
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNCPicker:
:path: "../node_modules/@react-native-picker/picker"
RNCPushNotificationIOS:
:path: "../node_modules/@react-native-community/push-notification-ios"
RNFastImage:
Expand Down Expand Up @@ -918,6 +924,7 @@ SPEC CHECKSUMS:
GTMSessionFetcher: 43748f93435c2aa068b1cbe39655aaf600652e91
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
libwebp: 98a37e597e40bfdb4c911fc98f2c53d0b12d05fc
mobile-ffmpeg-https: 311fc4a8f671cf36d1d6b8f421e8246b790978d9
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
OGReactNativeWaveform: f789fabadbf3904c7cba84d183405395861b8fed
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
Expand All @@ -937,6 +944,7 @@ SPEC CHECKSUMS:
react-native-camera: 3eae183c1d111103963f3dd913b65d01aef8110f
react-native-document-picker: f4cc4df2eff8c9015d862a59bdaef11a153f1292
react-native-fbsdk-next: a0dd8905af573ec4d21b7bc398423ccaa2ce2b07
react-native-ffmpeg: 587fa045f985d775107f4b8cbb6c79df0ad68e63
react-native-get-random-values: 237bffb1c7e05fb142092681531810a29ba53015
react-native-image-picker: 31971f6184e7c1dcb4fc1f122e1ba2c3fb11ef1e
react-native-netinfo: 92e6e4476eb8bf6fc2d7c0a6ca0a1406f663d73a
Expand Down Expand Up @@ -967,7 +975,6 @@ SPEC CHECKSUMS:
RNCCheckbox: 6bd119c26c6eb8264a29d59ff66cb70a14de3349
RNCClipboard: 99fc8ad669a376b756fbc8098ae2fd05c0ed0668
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNCPicker: 2568e0d0b4644dd9d5f2cec9eca197f5f3f5acb3
RNCPushNotificationIOS: 87b8d16d3ede4532745e05b03c42cff33a36cc45
RNFastImage: 1f2cab428712a4baaf78d6169eaec7f622556dd7
RNFBAnalytics: 3e250066a98d6ea0a7816c52de75f2633f726580
Expand All @@ -991,6 +998,6 @@ SPEC CHECKSUMS:
Yoga: 575c581c63e0d35c9a83f4b46d01d63abc1100ac
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 44e78e2685b99e5e754eaa6de4494bd645a4ce19
PODFILE CHECKSUM: 0789ab851d66260b29c1e4c0488a7cee005fdf18

COCOAPODS: 1.11.2
14 changes: 14 additions & 0 deletions ios/RNWaveformManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// RNWaveformManager.m
// ethora
//
// Created by Михайло Могилюк on 16.11.2021.
//


#import "React/RCTBridgeModule.h"


@interface RCT_EXTERN_MODULE(RNWaveform, NSObject)
RCT_EXTERN_METHOD(loadAudioFile: (RCTPromiseResolveBlock *)resolve rejecter:(RCTPromiseRejectBlock * )reject)
@end
52 changes: 52 additions & 0 deletions ios/RNWaweform.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// RNWaweform.swift
// ethora
//
// Created by Михайло Могилюк on 16.11.2021.
//

import Foundation
import React
import AVFoundation
import FDWaveformView


@objc (RNWaveform)
class RNWaveform : NSObject {


// Calling a routine & get response back

func json(from object:Any) -> String? {
guard let data = try? JSONSerialization.data(withJSONObject: object, options: []) else {
return nil
}
return String(data: data, encoding: String.Encoding.utf8)
}
@objc(loadAudioFile:rejecter:)
func loadAudioFile(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
let recordingName = "hello.m4a"
let dirPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first
let desURL = dirPath?.appendingPathComponent(recordingName)

// let pathArray = [dirPath.absoluteString, recordingName]
// let filePath = URL(fileURLWithPath: pathArray.joined(separator: "/"))

let file = try! AVAudioFile(forReading: desURL!)
let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: file.fileFormat.channelCount, interleaved: false)!

let buf = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: 1024)!
try! file.read(into: buf)

// this makes a copy, you might not want that
let floatArray = Array(UnsafeBufferPointer(start: buf.floatChannelData?[0], count:Int(buf.frameLength)))

let result: NSMutableArray = []
for item in floatArray {
result.add(item)
}

resolve(result)

}
}
15 changes: 15 additions & 0 deletions ios/RTCWaveformModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// RTCWaveformModule.h
// ethora
//
// Created by Михайло Могилюк on 16.11.2021.
//
#import <React/RCTBridgeModule.h>
@interface RTCWaveformModule : NSObject <RCTBridgeModule>
@end

#ifndef RTCWaveformModule_h
#define RTCWaveformModule_h


#endif /* RTCWaveformModule_h */
Loading