last day (15 days later) » 

8:52 PM
3
A: Play sound continuosly until user stops

Mike M.When you instantiate a MediaPlayer with create(), it is returned in a prepared state and you must not call prepare() on it. In your case, this is throwing an Exception, and therefore mp.setLooping(true) isn't being called.

 
Works that way! Anyway, now I can't stop the alarm touching the screen, the sound keeps playing all the time. What is wrong with the onTouchEvent method?
 
Where is onTouchEvent()? If it's a member of your Activity, make sure you don't have any other Views consuming the touch event.
 
Well, I have a main activity where I manage all the global methods and where this method is defined, but the UI consists on 3 fragments, and I use viewPager to navigate through them.
 
Then you probably want to override dispatchTouchEvent() in your Activity, instead of onTouchEvent().
 
Ok Mike, could you edit your post with this method? Or is it the same structure as onTouchEvent?
 
8:52 PM
Yep, same setup. Keep in mind, though, if you return true, the touch event will stop there. That is, it won't click any Buttons, etc.
 
Just changing onTouchEvent(MotionEvent event) for dispatchTouchEvent(MotionEvent event) force closes the app. About returning true, how should I code then not to happen that?
 
What's the error? Make sure you change the super method call, too.
 
There is no error on logcat :S the app just force closes, that's all ¿?
 
Did you change return super.onTouchEvent(event);?
 
Yeah return super.dispatchTouchEvent(event); but not working
 
8:52 PM
Where is this method? Also, you must be getting some error. Make sure you don't have any filters on your logcat that are restricting output.
 
I've deleted all logCat filters but still it is blank. It doesn't throw any error. My code consists on one MainActivity where I manage all global methods. Then I have 3 fragments, one for each app screen. The MainActivity doesn't have UI, it just implements the viewPager. Maybe should I call mediaplayer on each fragment and also implement onTouchEvent() on each fragment?
 
I don't know what to tell you. I just ran a test with an Activity, a ViewPager, Fragments, a MediaPlayer, and the dispatchTouchEvent() method overridden, and I got no errors. You might try cleaning and rebuilding the project, restarting the IDE, etc.
 
Ok Mike, don't worry, the OP question is solved so I'll accept your answer and I'll try few things. Thanks
Mike, I'll appreciate that you could post an answer with this idea in the new thread I've created for this question: stackoverflow.com/questions/25605803/…
 
I'm wrong. That's not gonna work. You can probably subclass ViewPager to override onInterceptTouchEvent(), but I've not tested it, and I'm on my way out shortly. When you tried the dispatchTouchEvent() override, did it force close upon starting the app, or when you touched it?
 
It get's closed when I touch the screen
 
8:52 PM
Well, until I get time later to test, all I can suggest for now, since you're not getting anything in the logcat, is to comment out lines in dispatchTouchEvent() to see which exactly is the problem. Also, could you just use a Button to do this? You could hide it afterward if needed.
 
Ok, I'll try also using a try catch statemnt, maybe there is any exception that isn't being caught... don't know...
Mike, I've been able to see the in the logcat what is the error, but I don't know how to solve. I'm leaving home now, tomorrow will update the post with the LogCat
 

last day (15 days later) »