在 Android 应用程序中加载广播电台时显示缓冲

发布于 2024-11-01 11:23:04 字数 442 浏览 4 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-11-08 11:23:04

使用广播意图。将服务与 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文