I wanted to pass a MediaStream object within a Fragment to an Activity using the Navigation Component. The MediaStream class belongs to WebRTC. So, I could not touch it to make it parcelable or serializable for passing the object around.
Here is the code from the fragment:
// Creating a PeerConnection with two callbacks
// one is triggered when an ICE candidate is received
// the other one is triggered when a MediaStream is received
localPeer = peerConnectionFactory.createPeerConnection(
rtcConfig,
object: CustomPeerConnectionObserver("localPeerCreation"){
override fun onIceCandidate(iceCandidate: IceCandidate?) {
// not relevant for this talk
}
override fun onAddStream(mediaStream: MediaStream?) {
super.onAddStream(mediaStream)
// TODO: create a new Activity and pass media stream to it for displaying
StreamsFragmentDirections.actionStreamsFragmentToStreamActivity(mediaStream)
}
})!!
As the TODO line implies, my initial goal was to pass the MediaStream object to a new Activity which should display the stream.
But I did not know how to do it. In the Navigation Graph Editor, I selected <inferred type> as type for mediastream but that not worked out as expected. Here, the relevant part from the navigation graph xml layout:
<activity
android:id="@+id/streamActivity"
android:name="com.john.elia.ui.activities.StreamActivity"
android:label="StreamActivity" >
<argument
android:name="mediaStream" />
</activity>
But the compiler complains, saying that it expected an Int but found a MediaStream.
How can I pass the MediaStream object ? In all the examples I have found they only show how to pass primitive types like a String, Int etc. How about objects with custom types?