- Bluetooth audio controls in Android
- 3 Answers 3
- Bluetooth music player for Android
- The idea
- Third-party software
- Instruction
- Bluetooth music player for Android: Video
- Приложение Bluetooth music player для Android
- Реализуемая идея
- Стороннее ПО
- Инструкция по использованию
- Bluetooth music player для Android: Видео
- Media files streaming on Android via Bluetooth
- Video streaming
- Music streaming
- Between two smartphones
- From the phone on the PC
- From the PC to the phone
- Media files streaming on Android via Bluetooth: Video
- Bluetooth Player
Bluetooth audio controls in Android
My app streams music and I want to be able to pause/play/skip from any Bluetooth device that might support these buttons (car, headset, etc). When connected through a car’s bluetooth the audio comes through automatically, but the control buttons do not affect my app’s audio stream. It instead opens the default media player. How do I route these buttons to affect my app?
3 Answers 3
Have you registered a BroadcastReceiver in your app to listen to MEDIA_BUTTON events using AudioManager.registerMediaButtonEventReceiver() ?
After registering, the button events can be handled by processing the KeyEvent object attached in the extras as EXTRA_KEY_EVENT . For example:
@Override public void onReceive(Context context, Intent intent) < final KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event.getAction() != KeyEvent.ACTION_DOWN) return; switch (event.getKeyCode()) < case KeyEvent.KEYCODE_MEDIA_STOP: // stop music break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: // pause music break; case KeyEvent.KEYCODE_MEDIA_NEXT: // next track break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: // previous track break; >>
This Android Developer blog post also have some nice information on the subject.
I saw MEDIA_BUTTON events coming through the log, so this looks promising. I’ll give it a go tomorrow.
Further to the accepted answer, please be aware that one of the Keycodes has changed in Ice Cream Sandwich:
The keycode that gets passed for play/pause intent has changed in ICS. See this http://code.google.com/p/media-button-router/issues/detail?id=10#c5
The keycode that had been sent prior to ICS was KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE. Now there are two separate keycodes for play and pause (126 and 127).
It’s sending KEYCODE_MEDIA_PLAY (126) and KEYCODE_MEDIA_PAUSE (127).
Bluetooth music player for Android
This time, we will consider the Bluetooth music player for Android application. It is useful for people who want to synchronize the music on multiple phones via Bluetooth.
The idea
We would like to make several amendments to avoid misunderstanding why we do it. Our goal is to play the same songs simultaneously on both Android devices. We will not tell you how to play songs via Bluetooth headset, since it is easily done using standard methods, and it does not need a special Bluetooth Player for Android.
Third-party software
In the Google Play, the Bluetooth Music Player Free is the best music player for Bluetooth on Android, and perhaps the only player with the desired functionality. We will use it today.
If speaking briefly about the functional of the application, visually it looks like an ordinary simple music player, and it can be used instead of the default player to play tracks in headphones.
The main feature of the Bluetooth Music Player Free lies in the fact that it has distribution and reception modes of audio files streaming playback. We will discuss it later.
Instruction
Enable Bluetooth on both smartphones.
For simultaneous playback of audio tracks on devices, it is necessary to install this player on both devices.
On the smartphone, that stores songs:
- Press «Menu» at the top left.
- Click «Player mode».
- Choose «shareMUSIC over Bluetooth».
- Next, in the «Menu», go to «Music Library» to choose the desired song.
- Click the title of the song to start the playback.
- Choose «Menu».
- Go to the «Player mode».
- Choose «listenMUSIC over Bluetooth».
- In the list of devices, click the name of the desired phone to connect to it.
- You will see a window with the information about the connection. To start playing the current signal, select «Mute».
After these steps, your smartphones should simultaneously play the audio file. As stated by the application developer, the music will not just sound the same on the two devices, but it will be played in stereo (the first device will act as a left channel, and the second as a right).
Note: this program is optimized primarily for smartphones, so when you will run it on the tablet, you may face with some problems. This was confirmed in our practice (we could not select the top menu buttons). Perhaps, not every tablet have these problems.
Bluetooth music player for Android: Video
[rBlock name=after_video return=1]
Приложение Bluetooth music player для Android
В этот раз рассмотрим приложение из категории Bluetooth music player для Android: оно пригодится тем, кто хочет синхронизировать проигрываемую музыку на нескольких телефонах через Bluetooth.
Реализуемая идея
Хотим сразу внести несколько поправок, чтобы в дальнейшем у читателей не было недопонимания, для чего мы это делаем. Наша задача заключается именно в том, чтобы на обоих Android-устройствах воспроизводить одинаковые песни так, чтобы они играли синхронно. Мы не будем рассказывать, как воспроизводить песни на Bluetooth-гарнитуре, так как это легко делается стандартными методами и для этого не нужен специальный Bluetooth плеер для Android.
Стороннее ПО
В Google Play лучший музыкальный проигрыватель для Bluetooth на Android, да и вообще, пожалуй, единственный подобный плеер с нужным нам функционалом, – это Bluetooth Music Player Free; его мы и будем использовать.
Если говорить кратко о функционале приложения, визуально оно выглядит как обычный простой проигрыватель музыки, и его можно использовать вместо стандартного плеера для воспроизведения треков, например, в наушниках.
Основная особенность Bluetooth Music Player Free заключается в том, что он имеет режимы раздачи и приема потокового проигрывания аудиофайлов, про которые мы и поговорим ниже.
Инструкция по использованию
На обоих смартфонах включите Bluetooth.
Для синхронного воспроизведения аудиотреков на девайсах нужно, чтобы оба устройства имели данный плеер.
Скачайте и запустите приложение Bluetooth music player на обоих телефонах.
На том смартфоне, где хранятся песни:
- Нажмите на кнопку «Menu», которая находится слева сверху.
- Тапните по клавише «Player mode».
- Выберите пункт «shareMUSIC».
- Далее в пункте «Menu» нужно перейти по пункту «Music Library», чтобы выбрать желаемую песню.
- Тапните по названию песни для начала ее проигрывания.
На втором смартфоне:
- Аналогично с первым методом выберите клавишу «Menu».
- Перейдите в «Player mode».
- Выберите режим «listenMUSIC».
- В списке девайсов нажмите на имени первого телефона для подключения к нему.
- Высветится окно с информацией о подключении. Для начала проигрывания текущего сигнала выберите действие «Mute».
После этих действий два ваши смартфона должны синхронно проигрывать аудиофайл. Как заверяет разработчик приложения, при проигрывании музыки она не просто одинаково звучит на двух устройствах, а будет воспроизводиться в стереорежиме: то есть на одном устройстве будет левый канал, а на другом правый.
Примечание: данная программа оптимизирована, в первую очередь, под смартфоны, поэтому при запуске ее на планшетах могут возникнуть проблемы с использованием, что у нас на практике и подтвердилось (не выбирались верхние кнопки меню); возможно, эти проблемы характерны не для всех планшетов.
Bluetooth music player для Android: Видео
Media files streaming on Android via Bluetooth
We have prepared this article to tell our readers about the possibility of streaming via Bluetooth between devices. We will show how to broadcast multimedia files, as well as explain why you will not be able to stream video via Bluetooth on Android.
Video streaming
Let us start with the theory. If we want to broadcast via Bluetooth, it is necessary to understand that our bitrate of playable files should not exceed the bandwidth the wireless module.
The advantage of Bluetooth is not its high bandwidth, but the low power consumption and ease of use. On some devices, the speed of Bluetooth cannot exceed 1 Mb/s, which is not sufficient for the playback of the video with the normal quality.
Only starting with version 3.0, the highest speed of Bluetooth is 24 Mbit/s. Apparently, because of the limited number of users, this method has not found popularity in the development of programs with such a functionality. Therefore, more technologies have been invented, and they were implemented with Wi-Fi (Miracast and Chromecast). Here, the bandwidth can reach an average of 50 – 150 Mbit s, which will play even videos with a resolution of 4K.
Music streaming
As for audio, the speed of Bluetooth is enough. Therefore, we will show a few ways to broadcast audio files.
Between two smartphones
So in order to perform music streaming to other Android via Bluetooth, you will need to use third-party program that was specifically designed for this goal. It is called Bluetooth Music Player. It is completely free and available in the Google Play .
- Activate the wireless module on two smartphones.
- Run the downloaded player on both devices.
- Select «Menu» at the top left of the screen.
- Click «Player mode».
- Choose «shareMUSIC».
- After that, in the «Menu», open the «Music Library», to open the list of songs.
- Click the title of the audio file to start playing.
- In the main window of the player, click «Menu».
- Choose «Player mode».
- Activate the «listenMUSIC» mode.
- In the list of devices, select the name of the server phone.
- This will open a window with information about the currently playing track. Press «mute» to start playing the track on your device.
From the phone on the PC
Audio Streaming from Android on the PC via Bluetooth is implemented by the standard method on Windows 7, 8, 8.1 (except Windows 10 c update for September 2015). In addition, there are third-party programs that work through BT and Wi-Fi.
- Activate the wireless module on the phone and on your PC.
- On the PC, open the «Control Panel».
- Select the category «Hardware and Sound».
- Next, click «Devices and Printers».
- Click «Add a device» and wait for the name of your smartphone in the found devices.
- Select the name of your smartphone and click «Next» to add it and pair it.
- Then, in the list of the devices, click twice the name of your smartphone.
- In the new window, click «Connect» in front of the «To use PC’s speakers to listen to stereo …».
- Your phone will see the PC as an ordinary headset, and when playing music through a standard player, the sound will be played on the computer.
From the PC to the phone
Audio streaming from PC to Android via Bluetooth is not supported by standard methods by Microsoft. We did not find any program that could play an audio stream from your PC on your phone via Bluetooth. On the other hand, there are alternatives that work via Wi-Fi.
Media files streaming on Android via Bluetooth: Video
[rBlock name=after_video return=1]
Bluetooth Player
My car has a build-in Bluetooth audio. It could only be used to receive and make calls rather than stream music. Therefore, I created this application to play back music via mono Bluetooth headset. The main features of this application are:
* Enable you to enjoy music via Mono Bluetooth Headset by simulating the function of Bluetooth Streaming.
* The music files are organized by folders located in device’s SDCARD.
* The playback information is saved so that you could resume it easily next time.
* You could set up a timer to stop the player either in certain minutes or after certain music. It is quite useful if you want to enjoy music before sleep.
* Video playback
* Bookmark
* Supported media formats: «.3gp»,».mp4″, «.m4a», «.aac», «.ts», «.3gp», «.flac», «.mp3», «.mid», «.xmf», «.mxmf», «.rtttl», «.rtx», «.ota», «.imy», «.ogg», «.mkv», «.wav», «.amr», «.ape», “.wma”, «.avi»
Who should buy this application
If you have a such car like my or you have a mono Bluetooth headset which is designed for only make calls, you could try this application. This application may save your money used to buy a Stereo Bluetooth headset.
Who should not buy this application
If you are looking for a fancy or powerful music player, this application is not the best option for you.
I have tested several phones and Bluetooth headsets. The test can not cover all the devices and Bluetooth headsets. If the application does not work on your phone or does not work with your Bluetooth headset, please raise the bug at forum below.
If you have any suggestion or new feature request, please contact my email [email protected] or raise it at forum below.
To see the product update or news, please visit the Google+ page listed below.