react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

ios/apple: get streaming from icecast server, use 2 connections instead of 1

Open mbarsocchi opened this issue 2 years ago • 15 comments

UPDATE: this is true for iPhone emulator and real device

using Apple/ios and connecting to an Icecast streaming server, results in two connections to the server instead of one only. When I close the app one connection is released while the other still remains active (and it may result in additional cost to the user)

Video demo https://youtu.be/7IU_FyCeR-4

Steps To Reproduce

  1. Create an app that uses a track with an URL of an Icecast server, eg.
export const tracks = [
  {
    id: 1,
    url: "https://nr11.newradio.it:19027/stream",
    ......
    isLiveStream: true,
  }
];
  1. run the app but do not press play
  2. verify the number of connections in the admin page of the Icecast server (eg. https://nr11.newradio.it:19027/)
  3. press play --> the number is increased by two
  4. press stop, or close the app --> the number is decreased by one (only)

ADDITIONAL INFO: is you have admin access to the Icecast admin web page, you can also see that the 2 connections have, as User Agent,

AppleCoreMedia/1.0.0.20E247 (iPhone; U; CPU OS 16_4 like Mac OS X; it_it) [ip:xx.xx.xx.xx]

Environment Info: Using Ios/simulated device don't know about a real iPhone

results of npx react-native info

info Fetching system and libraries information...
System:
  OS: macOS 13.3.1
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 533.70 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 16.13.0
    path: ~/.nvm/versions/node/v16.13.0/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 8.1.0
    path: ~/.nvm/versions/node/v16.13.0/bin/npm
  Watchman:
    version: 2023.05.22.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/mbarsocchi/.rvm/rubies/ruby-2.7.6/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 34.0.0
    System Images:
      - android-34 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.2
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/mbarsocchi/.rvm/rubies/ruby-2.7.6/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.3
    wanted: 0.72.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

mbarsocchi avatar Aug 14 '23 10:08 mbarsocchi

Which version of react-native-track-player are you using? Can you demonstrate the same issue using the example app? This would rule out any possible mistake on your part.

puckey avatar Aug 15 '23 07:08 puckey

thank you for your suggestion. I'll definitely try the example app. I'll keep you update with the result

mbarsocchi avatar Aug 16 '23 09:08 mbarsocchi

react-native-track-player version is @4.0.0-rc07. I've used the example app with the only change to the playlist.json file (this is the whole playlist.json file):

[
  {
    "url": "https://nr11.newradio.it/proxy/radiocit?mp=/stream",
    "title": "Test Streaming",
    "artist": "Radio Città Aperta",
    "artwork": "https://rntp.dev/example/Longing.jpeg",
    "isLiveStream": true
  }
]

and running in ios it duplicates the connection to the icecast server. As you can see the URL is not the one of my first comment. This one is the "proxied" one so it uses port 80. With the old or the new url the behaviour is the same.

mbarsocchi avatar Aug 16 '23 09:08 mbarsocchi

Found the same behavior also on a real device. But it's not a systematic error, so sometime it may happen and sometimes not.

mbarsocchi avatar Aug 20 '23 18:08 mbarsocchi

Are you sure this is not an issue with Icecast's admin page?

puckey avatar Oct 02 '23 15:10 puckey

connection is, for sure, doubled. This means also that if I have a maximum number of, for example, 20 listeners for Icecast than I can not use all of these 20 because some of them are taken twice for a single user (and also it seems that they are quite-never released)

mbarsocchi avatar Oct 02 '23 15:10 mbarsocchi

Okay, that sounds pretty bad – I will be looking into it in the coming days.

puckey avatar Oct 02 '23 15:10 puckey

looking for a way to easily replicate this in order to track down what is going on.. what do you recommend?

puckey avatar Oct 03 '23 08:10 puckey

@puckey I think the cleanest way is to install an Icecast server, with a client streaming something, and use it with the react app. For example, you can install Icecast server on your computer, and connect a client to this Icecast server (the client can also be VLC streaming an audio file in loop). Then connect the react app to your computer (check connection/firewall configurations). For Icecast, you can find documentation here https://icecast.org/ I don't know how many details you need to understand the behaviour. The server I've used for this bug is the real server of the Webradio I'm in. For that server, I don't have access to a verbose log so, even if I can give you some type of access, probably is not so useful. If you have some more questions you can try to contact me directly, (maybe not on github) send me an email [email protected]

mbarsocchi avatar Oct 03 '23 08:10 mbarsocchi

@mbarsocchi could it be that you were using a debug build when you were seeing this? Or put in other words: were you able to replicate this issue with a release build?

puckey avatar Oct 03 '23 14:10 puckey

@puckey still I don't have a release build to test and, to be honest, also for debugging, I need a friend with the iPhone because I don't have one. This could definitely be a debug-build issue, but I don't have a way to verify it.

mbarsocchi avatar Oct 03 '23 14:10 mbarsocchi

I came here through googling this problem, I have the same issue with icecast2 native, and with a html5 web player in a different control panel (Mediacp). Looks like it's not an issue with the web player though..

I guess it might be a bug in the client components on iPhone, or perhaps in the communication with icecast that makes the client make 2 duplicate connections.

AxisNL avatar Nov 20 '23 21:11 AxisNL

@mbarsocchi I am experiencing the same issue with duplicated calls to my streaming endpoint, only for iOS. Android works fine.

Did you find any solution to this?

Some additional info

  • I am not using icecast, it's a simple nest backend server with an endpoint that streams an audio file.
  • I've tried all formats (I am using openAI's text-to-speech so I've tried mp3, aac, opus, and flac). All formats deliver the same results: Android works fine and the player only calls my endpoint once and starts streaming. iOS calls my endpoint twice: the first stream is not used and closed after a few milliseconds, and the second stream starts playing after buffering and plays the whole track through.
  • I have also tried calling the same endpoint through Postman, and the stream is called once and streams to the end, just like in the Android case. So this seems to be an issue related to RNTP only in the iOS case.
  • I have tried on both emulators and on my real iphone 14 Pro
  • To debug, I've added some listeners and logged the sequence of playback states that happen during this issue: State.Loading -> State.Paused. I am honestly not sure why the player goes into Paused, because on Android it goes into Ready.

Edit: I found this other issue which I think might be related.

GabrieleMazzola avatar Feb 04 '24 10:02 GabrieleMazzola

@GabrieleMazzola no solution! The only thing that I can add is that, as a webradio, we removed the Icecast server and use only a Shoutcast one. But this is not a solutin

mbarsocchi avatar Feb 04 '24 18:02 mbarsocchi

The same happens in the native html5 audio element

vassilis-panos avatar Feb 04 '24 19:02 vassilis-panos

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 05 '24 01:05 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar May 12 '24 01:05 github-actions[bot]