2011-03-25 83 views
2

我想在實現aidl接口的背景中運行MP3播放服務。這裏是我的AIDL接口:android使用服務來更新seekbar

interface MPInterface { 

       void clearPlaylist(); 

       void addSongPlaylist(in String song); 

       void playFile(in int position);  

       void pause(); 

       void stop(); 

       void skipForward(); 

       void skipBack(); 

       void test(in String track); 

       int getCurrentDuration(); 

       int getDuration(); 

     } 

後來我創建MediaPlayerService它實現上述MPInterface,然後將服務綁定到活動。正常的方法,如playFile(),stop()或pause()完美地工作。但他們都是背景任務。我希望我的服務和界面能夠與seekbar等UI元素進行交互(例如,當您觸摸seekbar mediaplayer尋找點或seekbar進度更新相應於mediaplayer進度時)。任何好的指針或教程來幫助我實現這一目標?

+0

我在這裏掙扎的一點是MediaPlayer實例只存在於Service的本地,只能通過接口進行交互。因此,我不能在活動中調用對象,並設置事件偵聽器(如onBufferingUpdate),以便相應地更新活動中的seekbar。 – ForeverNights 2011-03-25 00:02:33

回答

1

您可以使用BroadcastIntent嗎?它應該允許您從UI元素髮送數據,並且BroadcastReceiver可以連接到您的服務,然後將數據推送到它。只是一個想法。