Skip to content
Open
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
21 changes: 18 additions & 3 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
View,
Platform,
NativeModules,
TouchableOpacity
TouchableOpacity,
Alert
} from 'react-native';
const {SdkEditorModule} = NativeModules;

Expand Down Expand Up @@ -53,9 +54,20 @@ export default class App extends Component {
};
}

showBackgroundExportResult(message) {
Alert.alert(
'Background export result',
message,
[{ text: 'OK' }]
);
}

handleVideoExport(response) {
console.log('Export completed successfully: video = ' + response?.videoUri + '; videoPreview = '
+ response?.previewUri);
const message = `Export completed successfully: video = ${response?.videoUri}; videoPreview = ${response?.previewUri}`;

console.log(message);

this.showBackgroundExportResult(message)
}

handleSdkError(e) {
Expand All @@ -73,6 +85,9 @@ export default class App extends Component {
message = 'Missing video export result!';
case 'ERR_CODE_NO_HOST_CONTROLLER':
message = "Host Activity or ViewController does not exist!";
case 'ERR_FAILED_BACKGROUND_EXPORT':
message = "Failed to export video in the background";
this.showBackgroundExportResult(message);
case 'ERR_VIDEO_EXPORT_CANCEL':
message = "Video export is canceled";
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.vesdkreactnativecliintegrationsample

import com.banuba.sdk.export.data.ExportNotificationManager
import com.banuba.sdk.export.data.ExportResult
import com.facebook.react.bridge.*
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactApplicationContext
import android.util.Log


class BackgroundExportNotificationManger() : ExportNotificationManager {

companion object {
const val TAG = "ExportNotificationManger"

// Errors
private const val ERR_FAILED_BACKGROUND_EXPORT = "ERR_FAILED_BACKGROUND_EXPORT"
}

private var isExportInProgress = false

fun isExportInProgress(): Boolean {
return isExportInProgress
}

private var resultPromise: Promise? = null

fun setResultPromise(promise: Promise?) {
resultPromise = promise
if (!isExportInProgress){
resultPromise?.reject("ERR_VIDEO_EXPORT_CANCEL", "")
}
}

override fun showExportStartedNotification(){
isExportInProgress = true
Log.d(TAG, "Starting background export")
}
override fun showSuccessfulExportNotification(result: ExportResult.Success){
isExportInProgress = false
val videoUri = result.videoList.firstOrNull()?.sourceUri
val previewUri = result.preview
if (videoUri == null) {
resultPromise?.reject("ERR_MISSING_EXPORT_RESULT", "")
} else {
val arguments: WritableMap = Arguments.createMap()
arguments.putString("videoUri", videoUri.toString())
arguments.putString("previewUri", previewUri.toString())
resultPromise?.resolve(arguments)
}
}
override fun showFailedExportExportNotification(){
isExportInProgress = false
Log.w(TAG, "Failed background export")
resultPromise?.reject(ERR_FAILED_BACKGROUND_EXPORT, "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.banuba.sdk.core.EditorUtilityManager
import com.banuba.sdk.ve.ext.VideoEditorUtils.getKoin
import org.koin.core.context.stopKoin
import org.koin.core.error.InstanceCreationException
import com.banuba.sdk.export.data.ExportNotificationManager

class SdkEditorModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {

Expand Down Expand Up @@ -82,7 +83,16 @@ class SdkEditorModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
}
}

resultCode == Activity.RESULT_CANCELED -> resultPromise?.reject("ERR_VIDEO_EXPORT_CANCEL", "")
resultCode == Activity.RESULT_CANCELED -> {
val exportNotificationManager = getKoin().get<ExportNotificationManager>() as? BackgroundExportNotificationManger

if (exportNotificationManager != null) {
exportNotificationManager.setResultPromise(resultPromise)
} else {
// For Foreground export
resultPromise?.reject("ERR_VIDEO_EXPORT_CANCEL", "")
}
}
}
resultPromise = null
} else if (requestCode == OPEN_PHOTO_EDITOR_REQUEST_CODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import org.koin.core.context.startKoin
import org.koin.core.qualifier.named
import org.koin.dsl.module

import com.banuba.sdk.export.data.BackgroundExportFlowManager
import com.banuba.sdk.export.data.ExportFlowManager
import com.banuba.sdk.export.data.ExportNotificationManager

class VideoEditorIntegrationModule {

companion object {
Expand Down Expand Up @@ -82,6 +86,24 @@ private class SampleModule {
AudioBrowserMusicProvider()
}
}

single<ExportFlowManager> {
BackgroundExportFlowManager(
exportDataProvider = get(),
exportSessionHelper = get(),
exportNotificationManager = get(),
exportDir = get(named("exportDir")),
shouldClearSessionOnFinish = true,
publishManager = get(),
errorParser = get(),
exportBundleProvider = get(),
eventConverter = get()
)
}

single<ExportNotificationManager> {
BackgroundExportNotificationManger()
}
}
}

22 changes: 2 additions & 20 deletions ios/SdkEditorModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,6 @@ class SdkEditorModule: NSObject, RCTBridgeModule {
extension SdkEditorModule {
func exportVideo() {
guard let videoEditorSDK else { return }
let progressViewController = createProgressViewController()
progressViewController.cancelHandler = { videoEditorSDK.stopExport() }
guard let presentedVC = RCTPresentedViewController() else {
return
}
presentedVC.present(progressViewController, animated: true)

let manager = FileManager.default
// File name
let firstFileURL = manager.temporaryDirectory.appendingPathComponent("tmp1.mov")
Expand Down Expand Up @@ -427,18 +420,13 @@ extension SdkEditorModule {
// Export func
videoEditorSDK.export(
using: exportConfiguration,
exportProgress: { [weak progressViewController] progress in
DispatchQueue.main.async {
progressViewController?.updateProgressView(with: Float(progress))
}
}
exportProgress: nil
) { [weak self] (error, previewImageInfo) in
let success = error == nil
// Export Callback
DispatchQueue.main.async {
if success {
// Result urls. You could interact with your own implementation.
progressViewController.dismiss(animated: true)
let previewImageData = previewImageInfo?.coverImage?.pngData()
let previewImageUrl = FileManager.default.temporaryDirectory.appendingPathComponent("\(UUID().uuidString).png")
try? previewImageData?.write(to: previewImageUrl)
Expand All @@ -457,7 +445,7 @@ extension SdkEditorModule {
NOT REQUIRED FOR INTEGRATION
Added for playing exported video file.
*/
self?.demoPlayExportedVideo(videoURL: firstFileURL)
// self?.demoPlayExportedVideo(videoURL: firstFileURL)
} else {
self?.currentReject?("ERR_MISSING_EXPORT_RESULT", error?.errorMessage, nil)
// clear video editor session data and remove strong reference to video editor sdk instance
Expand All @@ -470,12 +458,6 @@ extension SdkEditorModule {
}
}
}

func createProgressViewController() -> ProgressViewController {
let progressViewController = ProgressViewController.makeViewController()
progressViewController.message = "Exporting"
return progressViewController
}
}

// MARK: - BanubaVideoEditorSDKDelegate
Expand Down