My exact problem, also. But, I found out it's the earbuds, not the phone. New 5$ earbuds, problem solved.
+
My exact problem, also. But, I found out it's the earbuds, not the tablet. I have a samsung tablet A. I even tried them on my phone and got the same issue (constant restarting and freezing until I unplugged them).