Class ShadowMediaPlayer


public class ShadowMediaPlayer
extends ShadowPlayerBase
Automated testing of media playback can be a difficult thing - especially testing that your code properly handles asynchronous errors and events. This near impossible task is made quite straightforward using this implementation of MediaPlayer with Robolectric.

This shadow implementation provides much of the functionality needed to emulate MediaPlayer initialization and playback behavior without having to play actual media files. A summary of the features included are:

Note: One gotcha with this shadow is that you need to either configure an exception using addException(DataSource, IOException) or a ShadowMediaPlayer.MediaInfo instance for that data source using addMediaInfo(DataSource, MediaInfo) or setMediaInfoProvider(MediaInfoProvider) before calling setDataSource(org.robolectric.shadows.util.DataSource), otherwise you'll get an IllegalArgumentException.

The current features of ShadowMediaPlayer were focused on development for testing playback of audio tracks. Thus support for emulating timed text and video events is incomplete. None of these features would be particularly onerous to add/fix - contributions welcome, of course!