开发者

Android. How to make view clickable when mediaplayer stops playback

开发者 https://www.devze.com 2023-01-20 04:05 出处:网络
I have Acvtivity that creates view and mediaplayer. I want to use OnCompletion event to make that view clickable. But it throws exception, I don\'t 开发者_开发问答know why. Probably, mediaplayer runs

I have Acvtivity that creates view and mediaplayer. I want to use OnCompletion event to make that view clickable. But it throws exception, I don't 开发者_开发问答know why. Probably, mediaplayer runs in another thread and cannot access elements from main ui thread? Thank you for any information


Use Activity.runOnUiThread() to make sure your code is running in the correct thread.

    //assuming this code is within an Activity class, you can
    //access this function directly. Otherwise you must
    //have a reference to an Activity object
    this.runOnUiThread(new Runnable() 
    {
        public void run()
        {
            //perform UI-thread only tasks
        }
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消