在 Android 应用程序中加载广播电台时显示缓冲
我正在 Android 中制作一个广播应用程序。我面临着一个特殊的问题。我知道这可能很简单,但只是不知道如何做到这一点。我确信有人会更早遇到类似的问题,我会在这里得到解决方案
我有一个显示电台列表的首页。一旦我单击这些站中的任何一个,就会启动一个新的活动,其中有一个包含播放、暂停、停止控件的视图。当此活动启动时,我还立即使用 startSevice()
方法调用一个新服务。所有媒体播放器处理都在此服务中完成。
现在,我需要在实际媒体播放开始之前显示进度对话框(缓冲)。为了表明我正在尝试在服务中创建一个 ProgressDialog,但它要求传递一个上下文,我想我需要传递调用此服务的活动的上下文,因为当我将当前上下文传递给它会抛出一个错误。
如何实现这一目标?有没有办法获取启动服务的活动的上下文?
如果没有,可能有其他方法可以实现此目的,即在媒体尚未开始播放时显示缓冲状态
I am making a Radio application in Android. I am facing a peculiar problem. I know this could be as easy but just not able to figure out how to do this. I am sure somebody would have faced a similar problem earlier and I will get a solution here
I have a first page that displays the list of stations. Once I click on any of these stations, a new Activity is started that has a View that has Play, Pause, Stop controls. When this activity is started, I also immediately invoke a new Service using startSevice()
method. All the media player handling is done in this Service.
Now, I have a requirement of showing a Progress Dialog (Buffering) before the actual Media play starts. To show that I am trying to create a ProgressDialog in the Service, but it is asking for a context to be passed, I suppose I need to pass the Context of the activity that has invoked this service, because when I pass the current Context to it, it throws an Error.
How to achieve this? Is there a way to get hold of the Context of the Activity that started the Service?
If not, what could be some other way to achieve this, that is showing the Buffering status while the Media has not started playing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用广播意图。将服务与 Activity 绑定,并以 1 秒的间隔向 Activity 广播缓冲进度。在 Activity 中创建一个接收器,用于接收广播并将其转换为 Activity 中的进度条。
我有一个问题也许你可以回答:我正在使用服务进行流式传输,就像你一样,但是当缓冲第一次开始时,我不清楚如何捕获音频开始播放的时间,以便我可以删除“缓冲”通知。我尝试了 OnBufferingUpdate 但它有一个百分比值来决定音频是否正在播放。谢谢。
Use Broadcast intents. Bind the service to the activity and broadcast the buffering progress at 1 second intervals to the activity. Create a receiver in the activity that receives the broadcast and translates it to the progress bar in the activity.
I have a question maybe you can answer: I'm streaming using a service, just the way you are, but when the buffering first starts, I'm not clear on how to capture when the audio starts playing so that I can remove the "buffering" notification. I tried OnBufferingUpdate but that has a percentage value the whether the audio is playing or not. Thanks.