显示一个常见的​​音乐播放器中的所有活动 [英] Showing a common music player in all activities

查看:112
本文介绍了显示一个常见的​​音乐播放器中的所有活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个乐队,它由几个不同的活动,如议程,新闻栏目,专辑节等等的应用程序。 因为它是一个乐队,我也喜欢玩乐队的歌曲的背景。

I'm working on an app for a band, which consists of several different activities such as an agenda, news section, album section et cetera. Since it's for a band, I would like to play the band's songs in the background.

这是没有这样的问题,但我想显示一个小的音乐播放器上的所有活动的底部,这样用户就可以随时停止,跳过或重放一首歌曲,如果他们想。这种情况的一个例子可以在移动视Roadie的应用中找到,例如

This isn't such a problem, but I would like to show a small music player on the bottom of all activities so users can always stop, skip, or replay a song if they want to. An example of this can be found in the apps of Mobile Roadie, for instance.

不过,我不知道如何做到这一点。我最好的猜测是创建一个音乐播放器类有自己的布局,包括这个在每个活动/布局的底部。但是,由于每一个活动开始在自己的线程,我猜这将重置玩家的每一项活动。

However I have no idea how to do this. My best guess is creating a music player class with its own layout, and including this at the bottom of each activity/layout. But since every activity starts in its own thread, I'm guessing this would reset the player for each activity.

那么,我将如何去增加一个常见的​​音乐播放器为我所有的活动,其中将保持音乐播放器的状态呢?

So, how would I go about adding a common music player to all of my activities, where the state of the music player would be maintained?

有关的例子,下载手机Q魔宝的任何音乐基础的应用程序,你就会明白我的意思。

For an example, download any of the music based apps of Mobile Roadie and you'll know what I mean.

我决定使用碎片,但我不知道我是否可以使用那些已经存在的活动。所有的例子,我发现专注于全新的项目,而不是已经存在的。 因此,在短期,你能创建片段,并利用它们在现有的活动? (如示出的音乐播放器上的现有活动日程的顶部)

I decided on using Fragments, but I'm not sure if I can use those in already existing activities. All the examples I found focus on completely new projects, and not already existing ones. So in short, can you create fragments and use them in already existing activities? (such as showing the music player on top of the existing agenda activity)

推荐答案

我建议你做下面的方法。由于音乐播放状态,必须在所有的活动予以保留,你必须使用一个服务来实现这一目标。你也需要一个控制面板,它必须从活动的独立存在。要做到这一点,最好的方法是使用片段的。创建一个片段连接到服务,并提供了一​​个用户界面来控制它,那么这个片段添加到所有在你需要它的活动。

I suggest you doing it the following way. Since music playing state must be retained in all the activities, you have to use a service to achieve this. Also you need a control panel, which must exist separately from activities. The best method to do it is by using fragments. Create a fragment which connects to the service and provides an UI to control it, then add this fragment to all the activities where you need it.

这篇关于显示一个常见的​​音乐播放器中的所有活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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