thyagoluciano / flutter_radio

Radio station streaming example with ExoPlayer and Flutter.
GNU General Public License v3.0
86 stars 41 forks source link

ios: url playing: only ip adress is accepted, not dns #41

Open daneed opened 4 years ago

daneed commented 4 years ago

Hi! On ios, if I want a net radio to be played by flutter radio, this works only, if the url is an IP address. If I try to add a radio by domain name, this won't get played on ios.

For example: "http://stm16.abcaudio.tv:25584/player.mp3" works only on Android. BUT "http://88.198.10.229:8056" works on both platform.

Other examples: http://88.198.10.229:8056 ok for both http://37.59.41.148:17212 ok for both http://uk7.internet-radio.com:8226 ok only for Android.

Do you have any idea about the reason? Maybe something around AVUrlAsset initialization?

daneed commented 4 years ago

...and...THE SOLUTION IS:

  1. open FlutterRadioPlugin.m, and add this function:
    - (NSURL*) getResolvedUrl:(NSURL*) url {
    struct hostent* remoteHostEnt = gethostbyname([[url host] UTF8String]);
    struct in_addr* remoteInAddr = (struct in_addr*) remoteHostEnt->h_addr_list[0];
    char* sRemoteInAddr = inet_ntoa(*remoteInAddr);
    NSString* hostIP = [NSString stringWithUTF8String:sRemoteInAddr];
    NSString* wholeURLString = [NSString stringWithFormat:@"%@://%@:%@", [url scheme], hostIP, [[url port] stringValue]];
    NSLog(@"lookupHostIPAddressForURL source: %@, result: %@", [url absoluteString], wholeURLString);
    return [NSURL URLWithString:wholeURLString];
    }
  2. then, in the code, instead of audioFileURL = [NSURL URLWithString:path]; write this: audioFileURL = [self getResolvedUrl: [NSURL URLWithString:path]]; !

Voilá! Now FlutterRadio can work with dns-based url-s, not only with ip-based ones. Cheers, Daneed.

MarcelSchweichlerKretzmann commented 4 years ago

Hi Daneed. I followed your instruction but when I want to build my App it failed and this error appears

Running Xcode build...                                                  

Xcode build done.                                            7,4s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode's output:
↳
    Command CompileSwift failed with a nonzero exit code
    Command CompileSwift failed with a nonzero exit code
    Command CompileSwift failed with a nonzero exit code
    Command CompileSwift failed with a nonzero exit code
    Command CompileSwift failed with a nonzero exit code
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:155:37: error: implicit declaration of function 'gethostbyname' is invalid in C99
    [-Werror,-Wimplicit-function-declaration]
        struct hostent* remoteHostEnt = gethostbyname([[url host] UTF8String]);
                                        ^
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:155:37: error: declaration of 'gethostbyname' must be imported from module
    'Darwin.POSIX.netdb' before it is required
    In module 'UIKit' imported from /Users/marcelkretzmann/musicApp/ios/Pods/Target Support
    Files/flutter_radio/flutter_radio-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:1
    6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/usr/include/netdb.h:275:17: note: previous declaration is here
    struct hostent  *gethostbyname(const char *);
                     ^
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:155:37: error: conflicting types for 'gethostbyname'
        struct hostent* remoteHostEnt = gethostbyname([[url host] UTF8String]);
                                        ^
    In module 'UIKit' imported from /Users/marcelkretzmann/musicApp/ios/Pods/Target Support
    Files/flutter_radio/flutter_radio-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:1
    6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/usr/include/netdb.h:275:17: note: previous declaration is here
    struct hostent  *gethostbyname(const char *);
                     ^
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:156:67: error: definition of 'hostent' must be imported from module
    'Darwin.POSIX.netdb' before it is required
        struct in_addr* remoteInAddr = (struct in_addr*) remoteHostEnt->h_addr_list[0];
                                                                      ^
    In module 'UIKit' imported from /Users/marcelkretzmann/musicApp/ios/Pods/Target Support
    Files/flutter_radio/flutter_radio-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:1
    6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/usr/include/netdb.h:112:8: note: previous definition is here
    struct hostent {
           ^
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:157:27: error: implicit declaration of function 'inet_ntoa' is invalid in C99
    [-Werror,-Wimplicit-function-declaration]
        char* sRemoteInAddr = inet_ntoa(*remoteInAddr);
                              ^
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:157:27: error: declaration of 'inet_ntoa' must be imported from module
    'Darwin.POSIX.arpa.inet' before it is required
    In module 'UIKit' imported from /Users/marcelkretzmann/musicApp/ios/Pods/Target Support
    Files/flutter_radio/flutter_radio-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:1
    6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/usr/include/arpa/inet.h:76:8: note: previous declaration is here
    char            *inet_ntoa(struct in_addr);
                     ^
    /Users/marcelkretzmann/.pub-cache/hosted/pub.dartlang.org/flutter_radio-0.1.8/ios/Classes/Flutter
    RadioPlugin.m:157:27: error: conflicting types for 'inet_ntoa'
        char* sRemoteInAddr = inet_ntoa(*remoteInAddr);
                              ^
    In module 'UIKit' imported from /Users/marcelkretzmann/musicApp/ios/Pods/Target Support
    Files/flutter_radio/flutter_radio-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:1
    6:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPho
    neSimulator13.5.sdk/usr/include/arpa/inet.h:76:8: note: previous declaration is here
    char            *inet_ntoa(struct in_addr);
                     ^
    7 errors generated.
    Command CompileSwift failed with a nonzero exit code
    Command CompileSwift failed with a nonzero exit code
    Command CompileSwift failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description
    warning: Capabilities for Signing & Capabilities may not function correctly because its
    entitlements use a placeholder team ID. To resolve this, select a development team in the Runner
    editor. (in target 'Runner' from project 'Runner')

Do you know what I can do?