How to prevent Raspberry Pi suddenly disconnecting from TV?

I have a few Raspberry Pi mini computers I use for various projects. One of which I use to stream movies from to my TV. I recently came across an issue with a new TV I bought (one of the big brands). I was watching a programme and about 15 minutes in I got a notification on the TV that the Pi has disconnected. I went back to source selection, the Pi was there. I restarted the movie, searched for the time it suddenly exited. Another 15 minutes later the same a happened again.

Long story short it all came down to a settings in minidlna.conf as opposed to an issue with the TV itself as I initially thought. If you also are faced with this, here is how to fix it.

Go to /etc/minidlna.conf

sudo nano /etc/minidlna.conf

Search for the following line

notify_interval=895

This is the so called SSDP notify interval, in seconds. The default is 895 seconds. Which is 14 minutes and 55 seconds. I think by now you understand how is this related to the disconnecting issue.

In order to get rid of the probelm I simply increased this value to 18,000 which is 5 hours. Most of the movies I watch do fit into this threshold.

Having the aboce line in the config file commented out does not mean the issue in your case is different as the default is 895 seconds, so you do need to set some value to override it. Once I changed the value and saved the changes I restart minidlna service using

sudo service minidlna restart

Enjoy your movies!