public static DataSource toDataSource(FileDescriptor fd) { return toDataSource(fd, 0, 0); }
public static DataSource toDataSource(String uri, Map<String, String> headers) { return toDataSource(uri); }
public static DataSource toDataSource(Context context, Uri uri, Map<String, String> headers) { return toDataSource(context, uri); }
@SuppressWarnings("ObjectToString") public static DataSource toDataSource(FileDescriptor fd, long offset, long length) { return toDataSource(fd.toString() + offset); }
public static DataSource toDataSource(Context context, Uri uri) { return toDataSource(uri.toString()); }
/** * Adds the given bitmap at the given time for the given data source. * Uses <tt>path</tt> to call {@link org.robolectric.shadows.util.DataSource#toDataSource(FileDescriptor)} and * then calls {@link #addFrame(DataSource, long, Bitmap)}. This * method is retained mostly for backwards compatibility; * you can call {@link #addFrame(DataSource, long, Bitmap)} directly. * * @param fd file descriptor of the data source. * @param time the playback time at which the specified bitmap * should be retrieved. * @param bitmap the bitmap to retrieve. */ public static void addFrame(FileDescriptor fd, long time, Bitmap bitmap) { addFrame(toDataSource(fd), time, bitmap); }
/** * Adds the given keyCode/value pair for the given data source. * Uses <tt>path</tt> to call {@link org.robolectric.shadows.util.DataSource#toDataSource(String)} and * then calls {@link #addMetadata(DataSource, int, String)}. This * method is retained mostly for backwards compatibility; * you can call {@link #addMetadata(DataSource, int, String)} directly. * * @param path the path to the data source whose metadata is being set. * @param keyCode the keyCode for the metadata being set, as used by {@link MediaMetadataRetriever#extractMetadata(int)}. * @param value the value for the specified metadata. */ public static void addMetadata(String path, int keyCode, String value) { addMetadata(toDataSource(path), keyCode, value); }
@Implementation protected void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException { setDataSource(toDataSource(context, uri, headers)); sourceUri = uri; }
@Implementation protected void setDataSource(FileDescriptor fd, long offset, long length) { setDataSource(toDataSource(fd, offset, length)); }
@Implementation protected void setDataSource(String path) throws IOException { setDataSource(toDataSource(path)); }
@Implementation protected void setDataSource(String uri, Map<String, String> headers) { setDataSource(toDataSource(uri, headers)); }
@Implementation protected void setDataSource(String path) { setDataSource(toDataSource(path)); }
@Implementation protected void setDataSource(String uri, Map<String, String> headers) throws IOException { setDataSource(toDataSource(uri, headers)); }
@Implementation protected void setDataSource(FileDescriptor fd, long offset, long length) throws IOException { setDataSource(toDataSource(fd, offset, length)); }
@Implementation protected void setDataSource(Context context, Uri uri) { setDataSource(toDataSource(context, uri)); }
@Test public void setDataSourceException_withAllowedException() { RuntimeException e = new RuntimeException("some dummy message"); addException(toDataSource(path), e); try { retriever.setDataSource(path); fail("Expected exception"); } catch (Exception caught) { assertThat(caught).isSameAs(e); assertThat(e.getStackTrace()[0].getClassName()) .named("Stack trace should originate in Shadow") .isEqualTo(ShadowMediaMetadataRetriever.class.getName()); } } }
@Test public void testSetDataSourceCustomExceptionOverridesIllegalState() { shadowMediaPlayer.setState(PREPARED); ShadowMediaPlayer.addException(toDataSource("dummy"), new IOException()); try { mediaPlayer.setDataSource("dummy"); fail("Expecting IOException to be thrown"); } catch (IOException eThrown) { } catch (Exception eThrown) { fail(eThrown + " was thrown, expecting IOException"); } }
@Test public void testSetDataSourceString() throws IOException { DataSource ds = toDataSource("dummy"); ShadowMediaPlayer.addMediaInfo(ds, info); mediaPlayer.setDataSource("dummy"); assertThat(shadowMediaPlayer.getDataSource()).named("dataSource").isEqualTo(ds); }
@Test public void testSetDataSourceUri() throws IOException { Map<String, String> headers = new HashMap<>(); Uri uri = Uri.parse("file:/test"); DataSource ds = toDataSource(ApplicationProvider.getApplicationContext(), uri, headers); ShadowMediaPlayer.addMediaInfo(ds, info); mediaPlayer.setDataSource(ApplicationProvider.getApplicationContext(), uri, headers); assertThat(shadowMediaPlayer.getSourceUri()).named("sourceUri").isSameAs(uri); assertThat(shadowMediaPlayer.getDataSource()).named("dataSource").isEqualTo(ds); }
@Test public void create_withResourceId_shouldSetDataSource() { Application context = ApplicationProvider.getApplicationContext(); ShadowMediaPlayer.addMediaInfo( DataSource.toDataSource("android.resource://" + context.getPackageName() + "/123"), new ShadowMediaPlayer.MediaInfo(100, 10)); MediaPlayer mp = MediaPlayer.create(context, 123); ShadowMediaPlayer shadow = shadowOf(mp); assertThat(shadow.getDataSource()) .isEqualTo( DataSource.toDataSource("android.resource://" + context.getPackageName() + "/123")); }