0

I am working on radio app for iPhone. app works fine on iPhone. Now I am supporting to CarPlay as well.

iPhone app is basically developed using ReactNative and using React-Native bridge I am communicating with Swift.

Now I am supporting CarPlay also, which is completely developed in Swift.

I am facing issue while dual straming.

The scenario is,

I am playing one station on iPhone, then I connect my iPhone to CarPlay, same station getting played on CarPlay. I am getting that stationID from react native to native swift. Then I change station on iPhone from station1 to station2. Then on CarPlay station1 stops and started playing station2. Then I choose station3 on iPhone, then expected is station2 should stop on CarPlay and start playing Station3, but now here both station that is station2 and station3 started streaming. May be one is getting played on iPhone and other is getting played on CarPlay. but as iPhone is connected to CarPlay audio is coming out from CarPlay device.

I want to stop player on iPhone whenever iPhone got connected to CarPlay. Any station is selected on phone, its ID is sent to CarPlay and CarPlay should start playing the station.

For sending back values from Swift to ReactNative I have use EventEmitter, but thats not working as expected.

Can any one please help me to solve this issue.

Bridging file where I get selected station from phone to carplay.

@objc func setCarplayPlayingStationParameter(_ stationIDforCarPlay : String) {
    playingStationID = stationIDforCarPlay
  }

Event emmiter to call that carplay is connected and playing station

RNEventEmitter.emitter.sendEvent(withName: "RNCarPlayPlayingStation", body: nowPlayingStation)

At ReactNative side, handler to catch event

const stationListenerFromCarPlay = eventEmitter.addListener('RNCarPlayPlayingStation', onStationSelectAtCarPlay);

and method to stop player

const onStationSelectAtCarPlay = () => {
      stop();
  }

can anyone help what i am doing wrong, or give me some inputs to solve this multiple streaming issue.

Thanks.

2
  • "May be one is getting played on iPhone and other is getting played on CarPlay. but as iPhone is connected to CarPlay audio is coming out from CarPlay device". That's not how CarPlay works. CarPlay is just a second screen connected to your app. There is only one instance of your app running. Your problem is that you are not managing your player objects to ensure that you have only one active player. Either the Swift code or the React Natuve code should be responsible for playing audio. Not both.
    – Paulw11
    Commented Aug 9, 2024 at 21:30
  • @Paulw11 : Yes I checked that the way you mentioned, and got to know that reactNative code is responsible for playing audio. I just want to tell reactNativeCode that whenever CarPlay is connected and audio starts playing from Swift then stop playing audio from reactNativeSide. For the same I used eventEmiiter which is telling reactNative that Audio is getting played from Swift side, its coming into reactNative too, but still not stopping the audio.
    – Sagar
    Commented Aug 14, 2024 at 7:47

0

Browse other questions tagged or ask your own question.