如何知道什么时候声音开始在机器人玩 [英] how to know when audio is started playing in android

查看:139
本文介绍了如何知道什么时候声音开始在机器人玩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想启动音乐播放器的时候,用户启动的,当它stops.I不想启动任何音乐播放器,在我的应用程序的结束时间。我只是想在设备跟踪用户活动。所以我想,当用户启动音乐我的申请得到任何通知。

In my application I want to get start time of music player when user started and end time when it stops.I don't want to start any music player in my app. I just want to track user activity in device. So i want my application to get any notification when user started the music .

我是否得到任何意图的音乐播放器开始,它stopped.Or做我得到任何的意图,当用户打开音乐文件。

Do I get any intent for music player started and it stopped.Or do I get any intent for when user opens music files.

有没有其他的方法比其他的意图当用户启动音乐播放器捕获的开始时间和和时间。

Is there any other method other than intent to capture the start time and and time when user starts music player.

推荐答案

那么你可以实现接口<一href="http://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html"相对=nofollow>AudioManager.OnAudioFocusChangeListener,其中有一种方法onAudioFocusChange,它可以让你知道,如果音频设备已更改,也可以告诉我们,如果重点是增加或减少。

Well you can implement the interface 'AudioManager.OnAudioFocusChangeListener' in which there is a method 'onAudioFocusChange' which lets you know if audio focus has been changed, and it can also tell if focus was gained or lost.

请参阅这个的链接,它解释了音频Focus在详情。应用程序必须通过请求获得音频焦点,并且可以实现AudioManager.OnAudioFocusChangeListener,如果有的聚焦增益,您可以检测,如果媒体播放器正在运行,(因为一些其他的应用程序,如你管可能获得重点发挥其音频),请参阅<一href="http://ganeshtiwaridotcomdotnp.blogspot.com/2011/10/android-$c$c-for-detecting-if-specific.html"相对=nofollow>这个来看看如何检测哪些应用程序或服务正在运行。你可以找到,如果声音已经开始玩了,如果是媒体播放器还是不行。

See this link, it explains the Audio Focus in detail. An application must gain audio focus through a request, and you can implement the 'AudioManager.OnAudioFocusChangeListener' and if there is focus gain, you can detect if the media player is running, (because some other application such as you tube may gain focus to play its audio), see this to see how to detect which application or service is currently running. You can find if audio has started to play, and if it was the media player or not.

希望这有助于。这是有趣的问题,我已经学到了一些新的东西,同时寻找答案!

Hope this helps. It was interesting question and I have learned some new things while searching for the answer!

这篇关于如何知道什么时候声音开始在机器人玩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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