<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bharat Verma on Medium]]></title>
        <description><![CDATA[Stories by Bharat Verma on Medium]]></description>
        <link>https://medium.com/@bharat2491?source=rss-1a3305a45481------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cUqfGwPXZT5pjxS-.jpg</url>
            <title>Stories by Bharat Verma on Medium</title>
            <link>https://medium.com/@bharat2491?source=rss-1a3305a45481------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:54:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bharat2491/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A tale of Musical Evolution in Android Media APIs]]></title>
            <link>https://medium.com/the-tech-life/a-tale-of-musical-evolution-in-android-media-apis-98af9dc14c94?source=rss-1a3305a45481------2</link>
            <guid isPermaLink="false">https://medium.com/p/98af9dc14c94</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[exoplayer]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Bharat Verma]]></dc:creator>
            <pubDate>Sun, 04 Sep 2016 13:28:36 GMT</pubDate>
            <atom:updated>2016-09-10T11:30:02.480Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pilot</h3><p>This tale is about the time when IceCream Sandwich(<em>Holo</em>) was launched and everybody was crazy about android mobiles. With whole new experience built around a cleaner, minimalistic design, Holo earned a place in heart of every user<em>. </em>Android OS<em> </em>versions were launched and discontinued, but one thing was common about all of them. There was an API known as MediaPlayer API in the heart of every Android SDK. With this API, Any android version would feel more living, more musical, more in demand.</p><h3>Young and Prosperous</h3><p>With the launch of Holo, MediaPlayer API has now come of age. It was young, well documented and easy to use. MediaPlayer API is adequately documented. It is a good example of abstraction and encapsulation. Let us see how.</p><p>Suppose we want to play a song from the Internet. Now playing an online song is a long and complex process. If a developer have to implement that by himself, he would have to handle many tasks by himself. Lets try to list a few of them:</p><ul><li>Networking</li><li>Buffering</li><li>Extraction</li><li>Decoding</li><li>Rendering</li><li>State Management</li></ul><p>these tasks have there own complexity and and learning curve. Other than these tasks there is also some playback logic that you need to write to handle current position, play, pause etc.</p><p>Now, it seems like a lot of things to handle. Moreover, there was no low level API in android SDK available to achieve many of these tasks. But Because we had MediaPlayer API available, playing an online song was a piece of cake. It was because of MediaPlayer API, that a developer didn’t have to bother about any of these low level tasks. Developer would just give a URI of Online/Local media file, and MediaPlayer would do the job.</p><p>Lets have a look on how Media Player works in Android when an MP3 song is streamed over network. Developer just have to write basic code :</p><pre>MediaPlayer mPlayer = new MediaPlayer();</pre><pre>mPlayer.setDataSource(url);</pre><pre>mPlayer.prepare();</pre><pre>mPlayer.start();</pre><p>and MediaPlayer would do the magic in background :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*9C6WHlZcFPVlAjmjstHaGg.jpeg" /><figcaption>MediaPlayer handles all low level tasks by itself.</figcaption></figure><p>Developers were using MediaPlayer API at its best. Many wonderful applications were build, technical blogs were written, talk were made, and users enjoyed the endless pleasure of good music applications on android smartphones all around the globe. <em>Everything was Perfect, everybody was happy.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lbdq9e32F9vGrs3Qs71QCA.gif" /></figure><h3>Perfection is the enemy of good</h3><p>As Time was running at its pace, innovative ideas were popping out of brilliant brains. With emerging need of optimisation and customisations, MediaPlayer API was used more intensively and aggressively. MediaPlayer API was like a holy saint, but with rise in expectations, other side of the coin just showed up. For instance:</p><ol><li>Developer wanted to locally persist the data buffered by MediaPlayer during streaming of a song which was not possible.</li><li>MediaPlayer API was capable to open only raw resources.</li><li>Some developer tried to read its code and create another player but because of no such low level API support, everybody was helpless.</li><li>If you try to pause a sound before it actually play (in prepare state), it throw IllegalStateException.</li><li>Same happens if you accidentally replay a sound again before preparing.</li><li>Game Developer was the biggest victim as they wanted to play multiple sound in a game.</li></ol><p>MediaPlayer was the only one capable to play media in android. It was found to be poorly designed, unpredictable and not flexible. The encapsulation and abstraction stopped it from being extensible. <em>Developers were living in despair, Once Saint was then popular as Draconian Devil.</em></p><h3>Spill the beans: <em>The Magic Beans</em></h3><p>Desperation and frustration among developers was growing. They wanted to use MediaPlayer, but with a twist. They wanted to do more with it. Expectations were legitimate and needed to be answered. Google(<em>read God of android world</em>) has figured it all out. In June 2012, new android version <strong><em>Jelly Bean</em></strong> was announced. With this update, Media API in android took a new turn. In Google IO 2012, new Media Player Low Level APIs were introduced. These APIs allowed user to bypass the MediaPlayer.java and allowed developer to handle media objects the way s/he wants.</p><p>These APIs were just a wrapper around native media code but this allowed a developer to <em>look beyond what you see. </em>The idea was to allow user to extract information from the media at low level. Now a user can extract tracks, samples, play with buffers, process video frame before rendering etc.</p><p>Lets have a brief look on these APIs. Some of the main attraction of this API are as follows :</p><ol><li><strong>MediaExtractor</strong> : MediaExtractor is one of the main class. This class allows you to extract media/media info from any media file supported by the hardware. A DataSource is passed to this class and this class will open the media file in bits and pieces for you. This class allows you to read all the tracks, sampleInfo etc. There is a lot that this class can do, but that is out of scope of this read.</li><li><strong>MediaCodec</strong> : MediaCodec class can be used to access low level encoder/decoder. <em>[Codec is basically a program that both compress media files so that it can be transferred with less latency and decompress if for viewing or editing.]. </em>MediaCodec class allow you to access any codec that is available on the hardware level. Without MediaCodec support, HLS is nearly impossible.</li><li><strong>MediaFormat : </strong>MediaFormat class represents the format of a given MediaType.</li><li><strong>MediaCodecList</strong> + <strong>MediaCodecInfo : </strong>These classes help you to know a) list all the codecs supported by a device b) information and capabilities of a particular MediaCodec type. These classes are nothing but a wrapper over a Registry XML file (<em>bundled with every device from Jellybean onwards</em>) that tells the codecs supported by this particular device at hardware level.</li></ol><p>With these classes, developers can now handle the media as they want. Lets try to categorise all low level tasks according to new APIs available to us :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*QaqSLSfdPbtSmZtzSuUoNQ.jpeg" /><figcaption>MediaPlayer with Low level APIs</figcaption></figure><p>As clear from the Diagram above, Networking, Buffering and Extraction can be achieved by MediaExtractor API. Decoding and video rendering can be achieved by MediaCodec class whereas audio rendering can be handled by AudioTrack.java which is already available since Cupcake release. So basically you can write your own media player with less effort and more flexibility.</p><h4><em>How this is better than old School MediaPlayer.java?</em></h4><ol><li>With the help of <strong>MediaExtractor and MediaCodec</strong>, We now have access to media data. We can persist it, extract relevant information from it, do image processing and much more.</li><li>We can now customise our networking, buffering and even extraction logic the way we want.</li><li>We can write support for any protocol as we like. e.g. you can write support for HLS(Http Live Streaming) and DASH protocols</li><li>We can encrypt our media or in other words, we can stream/play encrypted media files.</li></ol><p>Needless to say, you can update/extend the capabilities of your player.</p><p>Jelly<strong>bean</strong> update ended monopoly of <strong>MediaPlayer.java </strong>and opened gate for the scope of improvement in Music Application world</p><h3>Dawn of ExoPlayer</h3><p>With these new Low Level Media APIs, Google have already developed such a MediaPlayer which is known as <a href="https://google.github.io/ExoPlayer/">ExoPlayer</a>. ExoPlayer is an Application Level Media MediaPlayer with support for DRM encryption, HLS, DASH and almost all kind of media formats. It is designed in a way that make it flexible, easy to use, modify and extend.</p><p>ExoPlayer is already being used by Youtube, Wynk Music and other famous media applications. ExoPlayer has brought a new revolution in Media Application. We will discuss more about ExoPlayer in detail in coming posts.</p><p>PS: If you liked this article, please feel free to like, comment and share.</p><p>References :</p><blockquote><a href="https://google.github.io/ExoPlayer/">ExoPlayer</a> , <a href="https://www.youtube.com/watch?v=6VjF638VObA">ExoPlayer Introduction</a>, <a href="https://www.youtube.com/watch?v=RQws6vsoav8">Google IO 2012</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98af9dc14c94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-tech-life/a-tale-of-musical-evolution-in-android-media-apis-98af9dc14c94">A tale of Musical Evolution in Android Media APIs</a> was originally published in <a href="https://medium.com/the-tech-life">The Tech Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>