Exception Handling for Media Push
To optimize the user experience in Media Push scenarios and avoid frequent streaming exceptions, you can refer to this page to optimize your code logic.
onRtmpStreamingStateChanged
callback. If you are still using the onStreamPublished
callback, you need to refer to this page and What is the relationship between the old and new callbacks of Media Push? as well.Troubleshooting by error code
After you call startRtmpStreamWithTranscoding
or startRtmpStreamWithoutTranscoding
, you can troubleshoot using the error codes reported by the onRtmpStreamingStateChanged
callback.
onRtmpStreamingEvent
callback do not affect the streaming process, but are only used as event alerts. The errors reported by the onRtmpStreamingStateChanged
callback can cause the streaming to be interrupted, so refer to this page to troubleshoot accordingly when an error code is received.No troubleshooting required
RTMP_STREAM_PUBLISH_ERROR_OK (0)
: Streaming to CDN is successful.RTMP_STREAM_UNPUBLISH_ERROR_OK (100)
: The streaming is stopped normally.
Retry pushing the stream to the CDN
RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT (3)
: The request to the Agora streaming server timed out. Common reason: Network exception. Solution: CallstopRtmpStream
andstart
in turn to retry pushing the stream.RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR (4)
: An error occurred in the Agora streaming server. Solution: CallstopRtmpStream
andstart
in turn to retry pushing the stream.RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR (5)
: An error occurred in the CDN network or between the Agora streaming server and CDN network. Solution: CallstopRtmpStream
andstart
in turn to retry pushing the stream. If the streaming still fails after three to five attempts, contact the CDN vendor and Agora technical support in turn for troubleshooting.RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND (9)
: The streaming URL cannot be found. Solution: After checking and replacing the streaming URL you are passing, callstart
to retry pushing the stream.RTMP_STREAM_PUBLISH_ERROR_NET_DOWN (14)
: An error occurred in the host's network. Solution: CallstopRtmpStream
andstart
in turn to retry pushing the stream.
stop
and start
methods to retry pushing a stream, ensure that you call start
only after you receive the onRtmpStreamingStateChanged
callback reporting that the stop
call is successful.Miscellaneous troubleshooting
RTMP_STREAM_PUBLISH_ERROR_INVALID_ARGUMENT (1)
: Invalid parameter. Solution: Check API call sequences and passed parameters.RTMP_STREAM_PUBLISH_ERROR_ENCRYPTED_STREAM_NOT_ALLOWED (2)
: The pushed media stream is encrypted and cannot be pushed. See Media Stream Encryption.RTMP_STREAM_PUBLISH_ERROR_REACH_LIMIT (7)
: The streaming URL limit has been reached. The maximum number of streaming URLs peruid
is 10 for each channel under each project. Solution: Delete unused streaming URLs to make room before retrying.RTMP_STREAM_PUBLISH_ERROR_NOT_AUTHORIZED (8)
: Operation without permission. Common reason: Pushing media streams to a streaming URL that is being used by another host. Solution: Check the code logic.RTMP_STREAM_PUBLISH_ERROR_FORMAT_NOT_SUPPORTED (10)
: The format of the streaming URL is not supported. Solution: Check and replace the streaming URL.RTMP_STREAM_PUBLISH_ERROR_NOT_BROADCASTER (11)
: The user role is not host, so the user cannot use the Media Push function. Check your application code logic.RTMP_STREAM_PUBLISH_ERROR_TRANSCODING_NO_MIX_STREAM (13)
: TheupdateRtmpTranscoding
orsetLiveTranscoding
(deprecated) method is called to update the transcoding configuration in a scenario where there is streaming without transcoding. Check your application code logic.RTMP_STREAM_PUBLISH_ERROR_INVALID_APPID (15)
: Your App ID does not have permission to use the Media Push function. Refer to Prerequisites to enable the Media Push permission.
Repeatedly pushing the stream to the CDN on a timer
Under extremely poor network conditions, you might not receive callbacks when the client is disconnected from the Agora streaming server. Therefore, Agora recommends that, in addition to listening for callbacks, you set a one-minute timer in your application layer to call start
once every minute after the streaming starts. Using this strategy produces this result: If the current streaming is abnormal, you might receive the onRtmpStreamingStateChanged
callback reporting other error codes, or you might not receive the callback. You can troubleshoot according to the error code you receive or retry pushing the stream.
Sample code to retry pushing streams
The following sample code takes the C++ language as an example to show the code logic of calling stopRtmpStream
and start
in turn to retry pushing streams.
References
The page takes the C++ language as an example. If you are using APIs in another language, refer to the following API comparison:
C++ | Objective-C | Java |
---|---|---|
startRtmpStreamWithoutTranscoding | startRtmpStreamWithoutTranscoding | startRtmpStreamWithoutTranscoding |
startRtmpStreamWithTranscoding | startRtmpStreamWithTranscoding | startRtmpStreamWithTranscoding |
updateRtmpTranscoding | updateRtmpTranscoding | updateRtmpTranscoding |
stopRtmpStream | stopRtmpStream | stopRtmpStream |
onRtmpStreamingStateChanged | rtmpStreamingChangedtoState | onRtmpStreamingStateChanged |
onRtmpStreamingEvent | rtmpStreamingEventWithUrl | onRtmpStreamingEvent |