diff --git a/example/ios/Podfile b/example/ios/Podfile index 74b3de064..8d8f41327 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -6,7 +6,7 @@ if ENV['FLUTTER_FRAMEWORK_DIR'] == nil end target 'Runner' do - use_frameworks! + #use_frameworks! # Pods for Runner diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index c970fef37..addb321e8 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -23,6 +23,6 @@ SPEC CHECKSUMS: Flutter: d674e78c937094a75ac71dd77e921e840bea3dbf path_provider: f96fff6166a8867510d2c25fdcc346327cc4b259 -PODFILE CHECKSUM: cc70c01bca487bebd110b87397f017f3b76a89f1 +PODFILE CHECKSUM: 1003743f06ec24ad436e3271b83a8ca2bee2fed4 COCOAPODS: 1.3.1 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 90795fca8..36c2b50da 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 455984CF045E7248FDBA4DCF /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 052C5762A1BC7EF459D31AEF /* libPods-Runner.a */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -20,7 +21,6 @@ 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - D4D145CE445199D02A4BB696 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7A61067461BFDD732159749 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -39,6 +39,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 052C5762A1BC7EF459D31AEF /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; @@ -55,7 +56,6 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - C7A61067461BFDD732159749 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -65,7 +65,7 @@ files = ( 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, - D4D145CE445199D02A4BB696 /* Pods_Runner.framework in Frameworks */, + 455984CF045E7248FDBA4DCF /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -75,7 +75,7 @@ 5C125FCCF71FB432AA72B7B6 /* Frameworks */ = { isa = PBXGroup; children = ( - C7A61067461BFDD732159749 /* Pods_Runner.framework */, + 052C5762A1BC7EF459D31AEF /* libPods-Runner.a */, ); name = Frameworks; sourceTree = ""; @@ -295,14 +295,10 @@ inputPaths = ( "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", "${PODS_ROOT}/../../../../../opt/flutter/bin/cache/artifacts/engine/ios/Flutter.framework", - "${BUILT_PRODUCTS_DIR}/audioplayers/audioplayers.framework", - "${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/audioplayers.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/ios/Classes/SwiftAudioplayerPlugin.swift b/ios/Classes/SwiftAudioplayerPlugin.swift deleted file mode 100644 index 3794a0e0b..000000000 --- a/ios/Classes/SwiftAudioplayerPlugin.swift +++ /dev/null @@ -1,168 +0,0 @@ -import Flutter -import UIKit -import AVKit -import AVFoundation - -public class SwiftAudioplayerPlugin: NSObject, FlutterPlugin { - - var _channel: FlutterMethodChannel - - var player: AVPlayer? - var playerItem: AVPlayerItem? - - var duration: CMTime = CMTimeMake(0, 1) - var position: CMTime = CMTimeMake(0, 1) - - var lastUrl: String? - - fileprivate var isPlaying: Bool = false - - public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "bz.rxla.flutter/audio", binaryMessenger: registrar.messenger()); - let instance = SwiftAudioplayerPlugin(channel: channel); - registrar.addMethodCallDelegate(instance, channel: channel); - } - - init(channel:FlutterMethodChannel){ - _channel = channel - super.init() - } - - - public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - print("iOS => call \(call.method)") - - switch (call.method) { - case "play": - guard let info:Dictionary = call.arguments as? Dictionary else { - result(0) - return - } - guard let url:String = info["url"] as? String, let isLocal:Bool = info["isLocal"] as? Bool else{ - result(0) - return - } - - togglePlay(url, isLocal: isLocal) - case "pause": - pause() - case "stop": - stop() - case "seek": - guard let sec:Double = call.arguments as? Double else { - result(0) - return - } - seek(sec) - default: - result(FlutterMethodNotImplemented) - } - result(1) - } - - fileprivate func togglePlay(_ url: String, isLocal:Bool) { - print( "togglePlay \(url)" ) - if url != lastUrl { - playerItem?.removeObserver(self, forKeyPath: #keyPath(player.currentItem.status)) - NotificationCenter.default.removeObserver(onSoundComplete) - - playerItem = AVPlayerItem(url: isLocal ? URL(fileURLWithPath:url): URL(string: url)!) - lastUrl = url - - // soundComplete handler - NotificationCenter.default.addObserver( - forName: Notification.Name.AVPlayerItemDidPlayToEndTime, - object: playerItem, - queue: nil, using: onSoundComplete) - - if let p = player{ - p.replaceCurrentItem(with: playerItem) - } else { - player = AVPlayer(playerItem: playerItem) - - // stream player position - player!.addPeriodicTimeObserver(forInterval: CMTime(seconds: 0.2, preferredTimescale: CMTimeScale(NSEC_PER_SEC)), queue: nil, using: onTimeInterval) - } - - // is sound ready - player!.currentItem?.addObserver(self, forKeyPath: #keyPath(player.currentItem.status), context: nil) - } - - if isPlaying == true { - pause() - } else { - updateDuration() - player!.play() - isPlaying = true - } - - } - - func updateDuration(){ - print("ios -> updateDuration...") - if let d = player?.currentItem!.duration{ - - duration = d - print("ios -> updateDuration... \(d)") - if duration.seconds > 0{ - let mseconds = duration.seconds * 1000 - _channel.invokeMethod("audio.onDuration", arguments: Int(mseconds)) - } - } - } - - func onTimeInterval(time:CMTime){ - print("ios -> onTimeInterval...") - let mseconds = time.seconds * 1000 - _channel.invokeMethod("audio.onCurrentPosition", arguments: Int(mseconds)) - } - - func pause() { - player!.pause() - isPlaying = false - } - - func stop() { - if (isPlaying) { - player!.pause() - player!.seek(to: CMTimeMake(0, 1)) - isPlaying = false - print("stop") - } - } - - func seek(_ seconds: Double) { - let time = CMTime.init(seconds: seconds, preferredTimescale: 1); - playerItem?.seek(to: time); - } - - func onSoundComplete(note: Notification) { - print("ios -> onSoundComplete...") - self.isPlaying = false - self.player!.pause() - self.player!.seek(to: CMTimeMake(0, 1)) - _channel.invokeMethod("audio.onComplete", arguments: nil) - } - - /// player ready observer - override open func observeValue( - forKeyPath keyPath: String?, of object: Any?, - change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) { - print("observeValue \(String(describing: keyPath))") - if keyPath! == "player.currentItem.status" { - if (player!.currentItem!.status == AVPlayerItemStatus.readyToPlay) { - updateDuration() - } else if (player!.currentItem!.status == AVPlayerItemStatus.failed) { - _channel.invokeMethod("audio.onError", arguments: "AVPlayerItemStatus.failed") - } - } - } - - deinit{ - if let p = player{ - p.removeTimeObserver(onTimeInterval) - p.currentItem?.removeObserver(self, forKeyPath: #keyPath(player.currentItem.status)) - NotificationCenter.default.removeObserver(onSoundComplete) - } - } -}