Play any music from your Android device from this device on a connected bluetooth speaker or headphone!
How It Works
Songbird is an Android application which plays music from your local phone’s audio library. The list of songs on your device can be scrolled through at the bottom of the device through our quick setup of a RecyclerView sorted list. Select the item in which you would like to play. Click the item again to pause or choose another song to play by clicking on another item in the list.
This application also allows the user to play on a connected Bluetooth speaker or headphone set using the A2DP headset protocol. This protocol sends all user audio data in a high quality stream over bluetooth to the paired device. The protocol can handle if the music is in sync with the device. This means that for lost connections, other apps opening up, connecting an audio plug, making a phone call, and other interrupts from the device can all be handled by this device.
A notification handler allows the music to be controlled even when the user is not in the app or if the phone is turned off. This can easily be accessed by swiping the menu bar down or turning the screen off. The notification pop-up can handle pausing, playing, resuming, skipping and rewinding right in the toolbar, an important feature for any music player app.
Pre-requisites
- Android SDK 25
- Android Build Tools v25.0.2
- Android Support Repository
Goals Achieved
- Read music file from storage
- Display selection of files to play
- Tap selection to launch service
- Service plays sound data from file
- Play/Pause functionality
- Phone to phone Bluetooth connection
- Notification functionality
- Bluetooth A2DP handles media streaming
Challenges Encountered
- Figuring out the data passing for music data. The ability for stream music data is supported only for A2DP protocol. Music playing simultaneously in sync is a very difficult acheivement. The device needs to transfer frequency data and coordinate recieving and sending of data on both devices. The initial chat functionality we were working with allows to send data in letters, but sending Audio data seems to be the entire packet of music. Essentially this meant that the code would rather have to “download” on the recieving device which is a very difficult problem if you want to stream data simultaneously.
- Coordinating with null data was difficult because there are many cases where null could be an issue. Suppose no media is located on the device, how would you know your app is working. If there is no Bluetooth on your device, how can you show that the device is connected properly. What was nice is that the initial chat app had connecting protocol behavior shown in the log file on the screen. However, not all cases were implemented and we needed to find outlining situations where Bluetooth connection between devices can be securely supported.
- Find accurate media handling libraries was difficult. Eventually we noticed we would need to send small packets of data continuously to obtain simultaneous playing. While researching this task in depth with other application, this task proved to be unachievable because the amount of data that is sent has to recieved a specific way by that device and played back using the same interpreter.
Screenshots
Choose a device to connect to
Connection Success
Swipe down to see notification
The Team
Dylan Vanmali
I am a third year Computer Engineering student studying at the University of California Santa Barbara. If you would like to know more about me, feel free to learn more about me on my LinkedIn Page!
Patrick Vidican
I am a third year Statistics student with a passion for Computer Science. If you would like to know more about me, check out my LinkedIn Page!
Weekly Reports
Week 1: Dylan Vanmali
- Created a GitHub for our Android Project so both me and my lab partner can work on it at the same time. The starting code we are working with is the Bluetooth Chat application that Android Studio provides us in their sample file database.
- I had to recreate the sample Android Studio project because changing individual file names never updated the debugger system, so the code would not upload to my Android device. I refabricated the code to Songbird files, updated the logo to the one I created last week, and fixed GitHub so my lab partner can download a working system on his personal copy of the system as well.
- Removing chat functionality from the chat-based sample application was a much more difficult task then I expected. The chat functionality is slowly decreasing presence on this device, and by slowly removing each step, this help me understand the protocol interface of the Bluetooth Fragment and Service Files. Most chat functionality is removed since we find that there is no use of this concept for our project.
Week 1: Patrick Vidican
- This week, I combed through the code to identify what needs to be removed, and what can remain for the final iteration. We have to be able to strategically remove code we don’t need/use and recognize where our own classes and acitivities will need to fit in the existing application. With the cutting and pasting of code, one is bound to encounter bugs and crashes in the application. One particular source of crash is an IndexOutOfBoundsException that occurs when your device is not discoverable. Next steps will include adding more devices to the piconet and integrating them all with the sending and receiving of audio data.
Week 2: Dylan Vanmali
- Chat functionality is practically gone throughout the app and now it is time to focus on putting in the music files.
Week 2: Patrick Vidican
- Development of Songbird continued with the implementation of a model to handle music transfer. This model involved the use of the Android media routing API. This week, I implemented a simple way to route media directly from what is playing on the device. The plan was to route this media into our BlueToothMusicService after getting the code working on Dylan’s device as well, but it turns out that the API level on that device isn’t high enough to support the features we were trying to add to Songbird.
- We won’t be able to add more devices to our piconet until we solve this API issue first. First, we’ll update our AndroidStudio to whatever stuff came out during Google IO conference (try using Kotlin?) Then once we get the version issues resolved, we’ll rewrite the media routing business and see if music can be transmitted the way we expect.
Week 3: Dylan Vanmali
- Created website for the project page using GitHub Pages to generate a website for us. Updates will occur as the README.md file is being updated. The link to our website now at https://dvanmali.github.io/Songbird/
- Looked up ways to gather music data from the library located on the device. I may have to restart my app to incorporate a new view xml file to show my list view.
Week 3: Patrick Vidican
Kotlin is only officially supported on AndroidStudio 3.0, which Google has not released to stable just yet, so the idea of adding Kotlin to our code will not happen for this project just yet. Instead of a new feature, I discovered a bug with my device once Dylan updated our API to 25. It seems that we have included the entire .idea folder in our .gitignore, and my device requires some of the files in that folder. (modules.xml, I think). In addition, to test on my device, it seems that I have to enable the Android Support plugin as well (otherwise I can’t even get the app to run on my phone, which is connected via USB-C).
- More time will need to be spent next week in the investigation of these bugs and the eventual squashing of them all. Actual time spent on coding this week was a little light this week due to the two other projects being worked on at the same time, but Dylan and I have faith we will at least be able to get our worst case under wraps fairly soon.
Week 4: Dylan Vanmali
- Integrating music commands and taking care of music playing states. The music service works in a variety of situations such as playing, pausing, fast forwarding, going back, etc.
- Able to send music data over A2DP protocol. I found out that the disadvantage of this is that we can’t play on both devices with this protocol since all data is being sent directly to the reciever in high definition format.
Week 4: Patrick Vidican
- Last attempt at handling multiple devices via bluetooth. I am able to get two phones to connect, but getting the old BluetoothChatService to encode and send audio data LIVE to all the devices is proving to be a greater hurdle than what its worth. At the moment, we have music sending to one device, which is at least one of our basic use cases.