1

I have this function that plays a file using mediaplayer

public boolean playURL(final String playURL, int makeBig, final int ts){
    try{
        Player.current_url = playURL;
        final String hour = Utils.getHourFromUrl(playURL);
        final String date = Utils.getDateFromUrl(playURL);
        currentPlayingDate = date;    

        int minutes = ts/60;
        String minuteToSet = Utils.appendZeros(String.valueOf(minutes));

        final String dateString = hour+":"+minuteToSet;

        currentPlayingTime = dateString;

        stateHandler.removeCallbacksAndMessages(null);
        MainActivity.mediaPlayer.reset();
        MainActivity.mediaPlayer.setDataSource(playURL);
        MainActivity.mediaPlayer.prepare();
        MainActivity.mediaPlayer.seekTo(ts * 1000);

        //some more code 
}

It works fine, but sometimes, if I pass damaged file to it, and then press some keys, the app crashes with errors in debugger:

enter image description here

Note that if I just wait for it for several seconds, it won't crash and app will continue to work, it crashes only when I press some keys when mediaplayer is struggling to play damaged file.

I'm trying for hours to find solution for this and prevent the app crashing, but I can't. any help at all will be appreciated, thanks!

Edit 1: adding error logcat at the time crash happens: http://pastebin.com/raw/taVyrvqM

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49
Mister M
  • 1,539
  • 3
  • 17
  • 37
  • 1
    i don't think the logcat warnings are relevant, try switching your logcat filter to all messages, and switch the level to error. that's way you'll see error logs from all apps and services. also, you didn't post the crash stack-trace, please post it. – marmor Sep 19 '16 at 07:19
  • @Mister M you have to attach error logs. Now you have shared some warnings – Volodymyr Sep 19 '16 at 07:25
  • okay added the error logcat – Mister M Sep 19 '16 at 07:29
  • i think your probliem is simeilar to this http://stackoverflow.com/questions/3467205/android-key-dispatching-timed-out – Deepak John Sep 19 '16 at 08:07
  • Yes I saw that thread while searching, but none of the suggested solutions there helped this problem – Mister M Sep 19 '16 at 08:16
  • @MisterM are you doing something with mediaPlayer (like pausing) when user click on the screen? Also, it looks like you made mediaPlayer variable static, it'll almost certainly lead to memory leak... – Kai Sep 22 '16 at 02:48
  • Not screen, the app works on android TV using remote, so when user presses a certain button corresponding action takes place, for example channel switch or increase volume. – Mister M Sep 22 '16 at 06:19
  • Also, in this app I have many variables set to static, since the app is built on only one activity and classes I use are only to sort functions. It didn't occur to me memory leak could happen because of this though, could this problem be connected to that? – Mister M Sep 22 '16 at 06:21
  • Are you using any service? Yes then provide detail of it. – Pravin Divraniya Sep 25 '16 at 18:54
  • have you tried putting your function in another thread other than the ui/main thread. it is the most likely cause of your problem. – Yordan Sep 26 '16 at 06:17
  • @Yordan yes I have tried it but the result is same – Mister M Sep 26 '16 at 07:23
  • @PravinDivraniya no i'm not – Mister M Sep 26 '16 at 07:24
  • What happens when you use prepareAsync()? I think it will do the job for you. – Pravin Divraniya Sep 26 '16 at 07:52
  • already tried, but no help – Mister M Sep 26 '16 at 08:25
  • Yes I knew that u tried but what am I asking is the behavior of the problem is same as in case of prepare() or there is any difference? – Pravin Divraniya Sep 26 '16 at 08:33
  • It's exactly the same. This behavior also happens at other random times and I'm unable to find the source of the problem – Mister M Sep 26 '16 at 08:34

0 Answers0