danieloeh/AntennaPod — pull request #184 by TheRealFalcon (2013-05-02 04:15:03+00:00)
Title: Develop

Adding variable speed playback to the service. This doesn't include any GUI functionality yet, as I feel like how that is implemented could be a bit more contentious. I'll (or somebody else can) add that separately.

Explanation of changes:
The com.aocate stuff is a Presto client library that reimplements the MediaPlayer API while adding variable speed playback. Unfortunately, it only provides audio. Since I didn't want two different PlaybackService classes (one for audio, one for video) both doing mostly the same stuff, I created an interface called IPlayer that has all of the methods of the current MediaPlayer. I then subclassed the aocate MediaPlayer as AudioPlayer and the android MediaPlayer as VideoPlayer, both implementing the IPlayer interface. They're essentially wrappers of their supertypes so that I could keep a consistent interface.

Since we can't reuse the same MediaPlayer object for audio and video files, I made a few additional changes to the PlaybackService to use a different MediaPlayer object for every file being played.

Both MediaPlayer classes have their own nested interfaces that both expect their own type. In order to not duplicate callback code (i.e., one interface that takes com.aocate.*.MediaPlayer, and one that takes android.*.MediaPlayer, but otherwise have the exact same code), I added a DuckType class to essentially force the IPlayer interface onto those classes at runtime. I adapted the class from here: http://thinking-in-code.blogspot.com/2008/11/duck-typing-in-java-using-dynamic.html