Android的媒体播放器使用的服务 [英] Android Media Player using service

查看:388
本文介绍了Android的媒体播放器使用的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个的MediaPlayer 类来播放MP3文件。一切都很好,然后我的播放器停止播放,而这是在后台,我发现,我的问题是我没有在服务中创建它,所以我开始阅读有关的服务,以了解如何创建一个,并用它为我的球员

I created a MediaPlayer class to play mp3 files. Everything was fine, then my player stopped playing while it was in background and I found out that my problem was I did not create it in a service, so I started to read about services to learn how to create one and use it for my player.

我的问题是,什么是为我服务,我的应用程序之间沟通的最佳方式?我应该用邮件或发送意图或结合?

My question is, what is the best way for me to communicate between the service and my application? Should I use the message or send intents or bind it?

我也应该创造通知区域的UI,也显示进度缓冲。我创建了服务端的活动监听器或者有更好的办法?

I should also create a UI in notification area, also to show the progress buffering. Do I create a listener from the service side to the activity or there is better way?

我用这些例子来学习,但我没有学习如何使用的onBind方法尚未:

I used these examples to learn but I did not learn how to use the onBind method yet:

  • Example: Communication between Activity and Service using Messaging
  • http://www.sapandiwakar.in/technical/tutorial-how-to-manually-create-android-media-player-controls/

先谢谢了。

编辑:我需要有时会要求玩家给我在赛道的细节这是玩,而玩家告诉我缓冲的更新,所以我可以更新搜索栏。难道我不停地发送意图的球员,或者我应该使用的IBinder?

EDIT : I need to sometimes ask the player to send me the track details which is playing, and the player to tell me the buffer updates so i can update seek bar. Do I keep sending intents to players or should I use IBinder ?

推荐答案

要服务和活动之​​间的沟通,我preFER广播接收机。从服务发送广播,并在活动收到它。

To communicate between service and Activity, I prefer Broadcast Receiver. Send Broadcast from Service and receive it in Activity.

这篇关于Android的媒体播放器使用的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆