bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2.02k stars 848 forks source link

iOS: Warnings during build #425

Closed nohli closed 4 years ago

nohli commented 4 years ago

Update: Only https://github.com/luanpotter/audioplayers/issues/425#issuecomment-602231798 are sill there.

I didn't find these in other issues, maybe they are not important, but having >20 other plugins, these are the only warnings I get when building (Xcode offers suggestions on how to fix them):

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:88:37: incompatible pointer types sending 'FlutterEngine ' to parameter of type 'NSObject _Nonnull' [-Wincompatible-pointer-types]

                binaryMessenger:_headlessEngine];
                                ^~~~~~~~~~~~~~~

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:381:20: 'timeControlStatus' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    if (player.timeControlStatus == AVPlayerTimeControlStatusPlaying) {
                                                                     ^

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:381:41: 'AVPlayerTimeControlStatusPlaying' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    if (player.timeControlStatus == AVPlayerTimeControlStatusPlaying) {
               ^~~~~~~~~~~~~~~~~

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:386:27: 'timeControlStatus' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    } else if (player.timeControlStatus == AVPlayerTimeControlStatusPaused) {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:386:48: 'AVPlayerTimeControlStatusPaused' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    } else if (player.timeControlStatus == AVPlayerTimeControlStatusPaused) {
                      ^~~~~~~~~~~~~~~~~

▸ Compiling audioplayers_vers.c ▸ Linking auto_orientation ▸ Compiling audioplayers-dummy.m ▸ Compiling AudioplayersPlugin.m

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:88:37: incompatible pointer types sending 'FlutterEngine ' to parameter of type 'NSObject _Nonnull' [-Wincompatible-pointer-types]

                binaryMessenger:_headlessEngine];
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:381:20: 'timeControlStatus' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    if (player.timeControlStatus == AVPlayerTimeControlStatusPlaying) {
                                                                     ^

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:381:41: 'AVPlayerTimeControlStatusPlaying' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    if (player.timeControlStatus == AVPlayerTimeControlStatusPlaying) {
               ^~~~~~~~~~~~~~~~~

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:386:27: 'timeControlStatus' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    } else if (player.timeControlStatus == AVPlayerTimeControlStatusPaused) {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⚠️ /Users/builder/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.14.0/darwin/Classes/AudioplayersPlugin.m:386:48: 'AVPlayerTimeControlStatusPaused' is only available on iOS 10.0 or newer [-Wunguarded-availability]

    } else if (player.timeControlStatus == AVPlayerTimeControlStatusPaused) {
                      ^~~~~~~~~~~~~~~~~
suragch commented 4 years ago

I also met this problem. I'm supporting down to iOS 8. Is this going to cause a crash on versions under 10?

nohli commented 4 years ago

FYI I have already set IPHONEOS_DEPLOYMENT_TARGET = 10.0; and the warning appears anyway.

fengxuemiao commented 4 years ago

I also met this problem. how resolve?

suragch commented 4 years ago

I set the build target to 8.0 and tested on an iPhone 4s with iOS 9.3.5 and playing an mp3 file didn't cause a crash. That's not to guarantee that it won't crash in other situations but for me it is good enough to risk opening up the app for more users.

nohli commented 4 years ago

Maybe this can easily be fixed through Xcodes suggestion (it shows a Fix button to add an availability check):

In AudioplayersPlugin.m replace line 381 and following:

        if (player.timeControlStatus == AVPlayerTimeControlStatusPlaying) {
            // player is playing and pause it
            [ self pause:_currentPlayerId ];
            _isPlaying = false;
            playerState = @"paused";
        } else if (player.timeControlStatus == AVPlayerTimeControlStatusPaused) {
            // player is paused and resume it
            [ self resume:_currentPlayerId ];
            _isPlaying = true;
            playerState = @"playing";
        }

with:

        if (@available(iOS 10.0, *)) {
            if (player.timeControlStatus == AVPlayerTimeControlStatusPlaying) {
                // player is playing and pause it
                [ self pause:_currentPlayerId ];
                _isPlaying = false;
                playerState = @"paused";
            } else if (player.timeControlStatus == AVPlayerTimeControlStatusPaused) {
                // player is paused and resume it
                [ self resume:_currentPlayerId ];
                _isPlaying = true;
                playerState = @"playing";
            }
        } else {
            // Fallback on earlier versions
        }

This removes all but two warning messages.

luanpotter commented 4 years ago

@nohli I'm always all in favour of fixing warning messages. would you like to put out a PR with your suggested change?

nohli commented 4 years ago

@luanpotter ok I will try now (my first time)

luanpotter commented 4 years ago

@nohli lmk if you need any help :)

nohli commented 4 years ago

FYI I've added

  audioplayers:
    git:
      url: https://github.com/nohli/audioplayers
      ref: 5da702c

to my project and the above mentioned warnings disappear, except (those are still there):

▸ Compiling AudioplayersPlugin.m

⚠️  /Users/builder/programs/flutter/.pub-cache/git/audioplayers-5da702c975f629b3666fd257dbdb7fc0e3ce27ed/darwin/Classes/AudioplayersPlugin.m:88:37: incompatible pointer types sending 'FlutterEngine *' to parameter of type 'NSObject<FlutterBinaryMessenger> * _Nonnull' [-Wincompatible-pointer-types]

                    binaryMessenger:_headlessEngine];
                                    ^~~~~~~~~~~~~~~

▸ Compiling audioplayers_vers.c
▸ Compiling audioplayers-dummy.m
▸ Compiling AudioplayersPlugin.m

⚠️  /Users/builder/programs/flutter/.pub-cache/git/audioplayers-5da702c975f629b3666fd257dbdb7fc0e3ce27ed/darwin/Classes/AudioplayersPlugin.m:88:37: incompatible pointer types sending 'FlutterEngine *' to parameter of type 'NSObject<FlutterBinaryMessenger> * _Nonnull' [-Wincompatible-pointer-types]

                    binaryMessenger:_headlessEngine];
                                                                         ^

I've run flutter test, flutter analyze and build my app on my mac and via codemagic and tested it (including sounds) via TestFlight. All working with https://github.com/luanpotter/audioplayers/pull/465.

luanpotter commented 4 years ago

Thanks, @nohli !