Open davidNode8 opened 7 years ago
Did you set the right URL or have the permission?
Yes, I'm using the same URL as the first time I connect before the connection lost. When I connect for the first time, the code returns NetStream.Publish.Start.
Did it happen every time?
Yes, so here's the chronology :
I'm wondering if that's the right way to handle internet connection lost in the middle of streaming.
What server or host did you connect?
arut ngix RTMP Also, it can reconnect just fine when disconnected manually. The error just happen when it disconnected while the internet connection is lost.
No, the media server is handled by another team, so I can't change it.
For nginx-rtmp
, the app name should be specified in the configuration file.
rtmp {
server {
listen 1935;
application mytv {
live on;
}
}
}
Then you have to set your url as rtmp://host:1935/mytv/sssssss
Hi, @begeekmyfriend I'm the one who handles the media server. This is the current config file
rtmp {
server {
listen 1935;
chunk_size 4000;
application hls {
live on;
hls on;
hls_path /data/hls;
record_append on;
record all;
record_path /peeqr;
exec_publish curl -X POST -d 'video=$name' 'http://localhost:8080/api/watcher';
exec_publish_done curl -X DELETE -d 'video=$name' 'http://localhost:8080/api/watcher';
exec_record_done /convert.sh $path $dirname $basename;
allow publish all;
allow play all;
}
}
}
Anything I missed?
Also, previously the application will crash in this line on RtmpConnection class when the internet connection is lost while streaming
try {
//I added if (socket != null) here
socket.close();
Log.d(TAG, "socket closed");
} catch (IOException ex) {
Log.e(TAG, "shutdown(): failed to close socket", ex);
}
Then the url should be set as rtmp://host:1935/hls/ssss
.
By the way, you may use FFmpeg
command line to verify it by typing
ffmpeg -re -i test.mp4 -vcodec libx264 -acodec libfaac -f flv rtmp://host:1935/hls/ssss
@kenanchristian you can reconfig your configuration file as a simple example to check if it is OK as follows
rtmp {
server {
listen 1935;
application mytv {
live on;
}
}
}
@begeekmyfriend Yes, actually it's should be OK. I've tested it using ffmpeg 👍
After reading this thread, the problem only occurs when the app trying to RECONNECT automatically when the internet connection is bad, but it's going well when connecting for the FIRST time or when RECONNECT manually (pause).
It seems your server configuration that would respond NetStream.Publish.BadName
packet to the client when the stream is occupied but Yasea never produces this packet itself.
@davidNode8 the handler on connection exception is here
Yeah. I called stopPublish() method on onRtmpSocketException listener.
@begeekmyfriend Fixed the problem by adding drop_idle_publisher
directive to the media server config. So each time there' no data send, the name will be released so it can be used when connecting again
It seems that we find some new 'feature' on nginx-rtmp
.
I've set the application to call the srsPublisher.stopPublish(); method whenever the internet connection is lost. I called the stopPublish method on onRtmpSocketException listener. But, whenever I'm trying to reconnect, this code
String code = ((AmfString) ((AmfObject) invoke.getData().get(1)).getProperty("code")).getValue();
on RtmpConnection class will return NetStream.Publish.BadName instead of NetStream.Publish.Start. How should I handle this?