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.