Learning and Programming Days - DLNA Player
I got my HiBy R3 music player some time ago and I've been enjoying it a lot, and I recently started playing the DLNA portion of it.
Using DLNA with Android is a piece of cake thanks to an app called BubbleUPnP, for which I purchased the app license as it allows me to stream my media files without limitations compared with the free version. However, it is when it comes to the PC where I had difficulties finding a compatible DLNA-compatible software. All of which I tried were either buggy or were not able to play back the files to my HiBy R3. That's when I started researching about the DLNA/UPnP protocol and found some examples. I then started developing a software to fit my needs immediately.
DLNA is a protocol used to send media files to wireless players. It usually consists of a Server, Renderer, and a Controller:
Server: This is where the media files are stored. They are sent to the player by the controller or the player itself if it is able to browse the server
Renderer: This is the device that plays back the media file. The renderer can also be able to browse and play the media acting as a controller, but if the renderer is just a renderer, a controller is needed.
Controller: This is like a remote control. You choose the media file and the renderer device with this.
I found one great resource at CodeProject, which you can see here. It talked about how to communicate with DLNA devices and send media files to it, given you have a DLNA Server. It worked using my own HTTP server, but then I wanted to develop a software that allows me to play back my media locally. That's where the fun part began.
I then started researching about how to implement HTTP servers in C#. I found some examples which I tried and they seemed to work, but were not able to handle partial requests, which seems are needed for media playback as my player was sending partial requests in the HTTP header. That's when I also found this other great resource at CodeProject which implemented a simple DLNA server.
Since both codes are open source and their license allow its use in projects including modifying them to fit the needs of others, I used both of these as a base for my project.
I adapted the above codes to work with a player I designed. It allows you to select a rendered device to play back your music files, build a queue, and control your device with its Play, Pause, Stop, Previous and Next buttons. It also allows you to seek the track by using the slider and shows the track progress in real time! Clearly, this is my first app that deals with socket connections in particular, since this is all the software does. It's all about sockets!
You simply need to specify your machine's IP Address, choose a port and press the Apply button, then Scan for Media Renderers, select one, and then drag and drop your music files. Then press the Play button and enjoy your music!
When you play back a file, it is copied to your machine's RAM which is then used to send the media file to the renderer as it requests it when it sends the HTTP request. This means the software has its own internal web server, so you don't need a separate DLNA Server as this software does that, serving the files in the queue as it's being played.
This project is available at GitHub here: https://github.com/moisesmcardona/DLNA-Player
Tested with my Hiby R3 player, I can now enjoy true wireless music playback without the quality loss that happens during the Bluetooth transmission. This is all done via Wifi and the player does all the rendering using the original file. I've tested it with FLAC 16-bit/44.1Hz as well as MP3 files, which are working correctly.
I hope this tool is useful for others and this has been an incredible learning journey.Click to view this post on Steemit.