From 122a90b4fbb1d160ccba1a926fcd43a2282a1cc8 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Fri, 7 Aug 2020 04:08:02 +1000 Subject: [PATCH] Disable setCategory on macOS --- README.md | 18 +++++----- darwin/Classes/AudioPlayer.m | 3 ++ darwin/Classes/JustAudioPlugin.m | 33 ++++++++++--------- .../Flutter/GeneratedPluginRegistrant.swift | 2 ++ example/macos/Podfile.lock | 13 +++++++- example/pubspec.lock | 12 +++---- 6 files changed, 50 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8d78362..40399f6 100644 --- a/README.md +++ b/README.md @@ -12,19 +12,19 @@ A Flutter plugin to play audio from URLs, files, assets, DASH/HLS streams and pl | request headers | ✅ | ✅ | ✅ | | | DASH | ✅ | (untested) | (untested) | (untested) | | HLS | ✅ | ✅ | (untested) | (untested) | -| buffer status/position | ✅ | ✅ | (untested) | ✅ | +| buffer status/position | ✅ | ✅ | ✅ | ✅ | | play/pause/seek | ✅ | ✅ | ✅ | ✅ | -| set volume | ✅ | ✅ | (untested) | ✅ | +| set volume | ✅ | ✅ | ✅ | ✅ | | set speed | ✅ | ✅ | ✅ | ✅ | -| clip audio | ✅ | ✅ | (untested) | ✅ | -| playlists | ✅ | ✅ | (untested) | ✅ | -| looping | ✅ | ✅ | (untested) | ✅ | -| shuffle | ✅ | ✅ | (untested) | ✅ | -| compose audio | ✅ | ✅ | (untested) | ✅ | -| gapless playback | ✅ | ✅ | (untested) | | +| clip audio | ✅ | ✅ | ✅ | ✅ | +| playlists | ✅ | ✅ | ✅ | ✅ | +| looping | ✅ | ✅ | ✅ | ✅ | +| shuffle | ✅ | ✅ | ✅ | ✅ | +| compose audio | ✅ | ✅ | ✅ | ✅ | +| gapless playback | ✅ | ✅ | ✅ | | | report player errors | ✅ | ✅ | ✅ | ✅ | -This plugin has been tested on Android, iOS and Web, and is being made available for testing on MacOS. Please consider reporting any bugs you encounter [here](https://github.com/ryanheise/just_audio/issues) or submitting pull requests [here](https://github.com/ryanheise/just_audio/pulls). +Please consider reporting any bugs you encounter [here](https://github.com/ryanheise/just_audio/issues) or submitting pull requests [here](https://github.com/ryanheise/just_audio/pulls). ## Example diff --git a/darwin/Classes/AudioPlayer.m b/darwin/Classes/AudioPlayer.m index 696ff45..bba23fe 100644 --- a/darwin/Classes/AudioPlayer.m +++ b/darwin/Classes/AudioPlayer.m @@ -7,6 +7,7 @@ #import "ClippingAudioSource.h" #import #import +#include // TODO: Check for and report invalid state transitions. // TODO: Apply Apple's guidance on seeking: https://developer.apple.com/library/archive/qa/qa1820/_index.html @@ -865,9 +866,11 @@ _playResult = result; } _playing = YES; +#if TARGET_OS_IPHONE if (_configuredSession) { [[AVAudioSession sharedInstance] setActive:YES error:nil]; } +#endif [_player play]; [self updatePosition]; if (@available(macOS 10.12, iOS 10.0, *)) {} diff --git a/darwin/Classes/JustAudioPlugin.m b/darwin/Classes/JustAudioPlugin.m index cbf9c2c..982a260 100644 --- a/darwin/Classes/JustAudioPlugin.m +++ b/darwin/Classes/JustAudioPlugin.m @@ -1,6 +1,7 @@ #import "JustAudioPlugin.h" #import "AudioPlayer.h" #import +#include @implementation JustAudioPlugin { NSObject* _registrar; @@ -10,7 +11,7 @@ + (void)registerWithRegistrar:(NSObject*)registrar { FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"com.ryanheise.just_audio.methods" - binaryMessenger:[registrar messenger]]; + binaryMessenger:[registrar messenger]]; JustAudioPlugin* instance = [[JustAudioPlugin alloc] initWithRegistrar:registrar]; [registrar addMethodCallDelegate:instance channel:channel]; } @@ -29,20 +30,22 @@ /*AudioPlayer* player =*/ [[AudioPlayer alloc] initWithRegistrar:_registrar playerId:playerId configuredSession:_configuredSession]; result(nil); } else if ([@"setIosCategory" isEqualToString:call.method]) { - NSNumber* categoryIndex = (NSNumber*)call.arguments; - AVAudioSessionCategory category = nil; - switch (categoryIndex.integerValue) { - case 0: category = AVAudioSessionCategoryAmbient; break; - case 1: category = AVAudioSessionCategorySoloAmbient; break; - case 2: category = AVAudioSessionCategoryPlayback; break; - case 3: category = AVAudioSessionCategoryRecord; break; - case 4: category = AVAudioSessionCategoryPlayAndRecord; break; - case 5: category = AVAudioSessionCategoryMultiRoute; break; - } - if (category) { - _configuredSession = YES; - } - [[AVAudioSession sharedInstance] setCategory:category error:nil]; +#if TARGET_OS_IPHONE + NSNumber* categoryIndex = (NSNumber*)call.arguments; + AVAudioSessionCategory category = nil; + switch (categoryIndex.integerValue) { + case 0: category = AVAudioSessionCategoryAmbient; break; + case 1: category = AVAudioSessionCategorySoloAmbient; break; + case 2: category = AVAudioSessionCategoryPlayback; break; + case 3: category = AVAudioSessionCategoryRecord; break; + case 4: category = AVAudioSessionCategoryPlayAndRecord; break; + case 5: category = AVAudioSessionCategoryMultiRoute; break; + } + if (category) { + _configuredSession = YES; + } + [[AVAudioSession sharedInstance] setCategory:category error:nil]; +#endif result(nil); } else { result(FlutterMethodNotImplemented); diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index 1eb70d2..000d62a 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,10 @@ import FlutterMacOS import Foundation +import path_provider_macos import just_audio func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) } diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 3bb672b..de2ed1f 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -2,21 +2,32 @@ PODS: - FlutterMacOS (1.0.0) - just_audio (0.0.1): - FlutterMacOS + - path_provider (0.0.1) + - path_provider_macos (0.0.1): + - FlutterMacOS DEPENDENCIES: - FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`) - just_audio (from `Flutter/ephemeral/.symlinks/plugins/just_audio/macos`) + - path_provider (from `Flutter/ephemeral/.symlinks/plugins/path_provider/macos`) + - path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`) EXTERNAL SOURCES: FlutterMacOS: :path: Flutter/ephemeral/.symlinks/flutter/darwin-x64 just_audio: :path: Flutter/ephemeral/.symlinks/plugins/just_audio/macos + path_provider: + :path: Flutter/ephemeral/.symlinks/plugins/path_provider/macos + path_provider_macos: + :path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos SPEC CHECKSUMS: FlutterMacOS: 15bea8a44d2fa024068daa0140371c020b4b6ff9 just_audio: 1a11463e7e522bd4e8caa925b4247f1360cbe5a2 + path_provider: e0848572d1d38b9a7dd099e79cf83f5b7e2cde9f + path_provider_macos: a0a3fd666cb7cd0448e936fb4abad4052961002b PODFILE CHECKSUM: d8ba9b3e9e93c62c74a660b46c6fcb09f03991a7 -COCOAPODS: 1.7.5 +COCOAPODS: 1.9.3 diff --git a/example/pubspec.lock b/example/pubspec.lock index 0bdb2a9..40308b7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -21,7 +21,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0-nullsafety" charcode: dependency: transitive description: @@ -42,7 +42,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0-nullsafety" convert: dependency: transitive description: @@ -120,7 +120,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety" path: dependency: transitive description: @@ -237,7 +237,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0-nullsafety" uuid: dependency: transitive description: @@ -251,7 +251,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety" xdg_directories: dependency: transitive description: @@ -260,5 +260,5 @@ packages: source: hosted version: "0.1.0" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" + dart: ">=2.9.0-18.0 <2.9.0" flutter: ">=1.12.13+hotfix.5 <2.0.0"