Skip to content

Commit

Permalink
Update platform implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Huculak committed May 29, 2021
1 parent c071779 commit 6c05ac0
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 120 deletions.
24 changes: 17 additions & 7 deletions soundpool/example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -68,7 +68,6 @@
A1787106973A50AC6744129D /* Pods-Runner.release.xcconfig */,
305DD10C907F978DE604B06B /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -358,7 +357,10 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = pl.ukaszapps.soundpoolexample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -467,7 +469,8 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -480,10 +483,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = HAUM3DL748;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = pl.ukaszapps.soundpoolexample;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = pl.ukaszapps.soundpool.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -501,7 +508,10 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = pl.ukaszapps.soundpoolexample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
76 changes: 17 additions & 59 deletions soundpool/example/macos/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,32 @@ project 'Runner', {
'Release' => :release,
}

def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end
pods_ary = []
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
end

def pubspec_supports_macos(file)
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return false;
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
File.foreach(file_abs_path) { |line|
return true if line =~ /^\s*macos:/
}
return false
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
ephemeral_dir = File.join('Flutter', 'ephemeral')
symlink_dir = File.join(ephemeral_dir, '.symlinks')
symlink_plugins_dir = File.join(symlink_dir, 'plugins')
system("rm -rf #{symlink_dir}")
system("mkdir -p #{symlink_plugins_dir}")
flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end

# Flutter Pods
generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig'))
if generated_xcconfig.empty?
puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
generated_xcconfig.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join(symlink_dir, 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path]))
end
}

# Plugin Pods
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join(symlink_plugins_dir, p[:name])
File.symlink(p[:path], symlink)
if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml'))
pod p[:name], :path => File.join(symlink, 'macos')
end
}
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true
19 changes: 6 additions & 13 deletions soundpool/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
PODS:
- FlutterMacOS (2.0.0)
- soundpool (1.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- soundpool_macos (1.0.0):
- FlutterMacOS

DEPENDENCIES:
- soundpool (from `Flutter/ephemeral/.symlinks/plugins/soundpool/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- soundpool_macos (from `Flutter/ephemeral/.symlinks/plugins/soundpool_macos/macos`)

SPEC REPOS:
trunk:
- FlutterMacOS

EXTERNAL SOURCES:
soundpool:
:path: Flutter/ephemeral/.symlinks/plugins/soundpool/macos
FlutterMacOS:
:path: Flutter/ephemeral
soundpool_macos:
:path: Flutter/ephemeral/.symlinks/plugins/soundpool_macos/macos

SPEC CHECKSUMS:
FlutterMacOS: 2f1b456c4d9436c4d4d13919bd3be8ef03ba6322
soundpool: 10ad9ba33c47ad6f956b50cb44dba46787529216
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
soundpool_macos: 3bc0b8b238407516ad9b8afc2647670ff58124f9

PODFILE CHECKSUM: d8ba9b3e9e93c62c74a660b46c6fcb09f03991a7
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c

COCOAPODS: 1.10.1
3 changes: 3 additions & 0 deletions soundpool/example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/soundpool_macos/soundpool_macos.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/soundpool_macos.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
36 changes: 25 additions & 11 deletions soundpool/ios/Classes/SwiftSoundpoolPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
// TODO create distinction between different types of audio playback
let attributes = call.arguments as! NSDictionary
let maxStreams = attributes["maxStreams"] as! Int
let wrapper = SoundpoolWrapper(maxStreams)
let enableRate = (attributes["ios_enableRate"] as? Bool) ?? true
let wrapper = SoundpoolWrapper(maxStreams, enableRate)
let index = wrappers.count
wrappers.append(wrapper)
result(index)
Expand Down Expand Up @@ -61,6 +62,8 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
class SoundpoolWrapper : NSObject {
private var maxStreams: Int

private var enableRate: Bool

private var streamIdProvider = Atomic<Int>(0)

private lazy var soundpool = [AVAudioPlayer]()
Expand All @@ -69,8 +72,9 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {

private lazy var nowPlaying: Dictionary<Int, NowPlaying> = [Int: NowPlaying]()

init(_ maxStreams: Int){
init(_ maxStreams: Int, _ enableRate: Bool){
self.maxStreams = maxStreams
self.enableRate = enableRate
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand All @@ -81,7 +85,9 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
let rawSound = attributes["rawSound"] as! FlutterStandardTypedData
do {
let audioPlayer = try AVAudioPlayer(data: rawSound.data)
audioPlayer.enableRate = true
if (enableRate){
audioPlayer.enableRate = true
}
audioPlayer.prepareToPlay()
let index = soundpool.count
soundpool.append(audioPlayer)
Expand All @@ -101,7 +107,9 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
var value:Int = -1
do {
let audioPlayer = try AVAudioPlayer(data: cachedSound)
audioPlayer.enableRate = true
if (self.enableRate){
audioPlayer.enableRate = true
}
audioPlayer.prepareToPlay()
let index = self.self.soundpool.count
self.self.soundpool.append(audioPlayer)
Expand Down Expand Up @@ -150,8 +158,10 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
nowPlayingData = NowPlaying(player: audioPlayer, delegate: delegate)

audioPlayer.numberOfLoops = times ?? 0
audioPlayer.enableRate = true
audioPlayer.rate = Float(rate)
if (enableRate){
audioPlayer.enableRate = true
audioPlayer.rate = Float(rate)
}

if (audioPlayer.play()) {
streamsCount[soundId] = currentCount + 1
Expand All @@ -167,7 +177,9 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
} else if let previousUrl = audioPlayer.url {
audioPlayer = try AVAudioPlayer(contentsOf: previousUrl)
}

if (enableRate){
audioPlayer.enableRate = true
}
audioPlayer.prepareToPlay()
soundpool[soundId] = audioPlayer
} catch {
Expand Down Expand Up @@ -216,10 +228,12 @@ public class SwiftSoundpoolPlugin: NSObject, FlutterPlugin {
audioPlayer?.volume = Float(volume)
result(nil)
case "setRate":
let streamId = attributes["streamId"] as! Int
let rate = (attributes["rate"] as? Double) ?? 1.0
let audioPlayer: AVAudioPlayer? = playerByStreamId(streamId: streamId)?.player
audioPlayer?.rate = Float(rate)
if (enableRate){
let streamId = attributes["streamId"] as! Int
let rate = (attributes["rate"] as? Double) ?? 1.0
let audioPlayer: AVAudioPlayer? = playerByStreamId(streamId: streamId)?.player
audioPlayer?.rate = Float(rate)
}
result(nil)
case "release": // TODO this should distinguish between soundpools for different types of audio playbacks
stopAllStreams()
Expand Down
Loading

0 comments on commit 6c05ac0

Please sign in to comment.