1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ex.variablespeed; 18 19 import android.content.Context; 20 import android.media.MediaPlayer; 21 import android.net.Uri; 22 23 import java.io.IOException; 24 25 import javax.annotation.concurrent.Immutable; 26 27 /** 28 * Encapsulates the data source for a media player. 29 * <p> 30 * Is used to make the setting of the data source for a 31 * {@link android.media.MediaPlayer} easier, or the calling of the correct 32 * {@link VariableSpeedNative} method done correctly. You should not use this class 33 * directly, it is for the benefit of the {@link VariableSpeed} implementation. 34 */ 35 @Immutable 36 /*package*/ class MediaPlayerDataSource { 37 private final Context mContext; 38 private final Uri mUri; 39 private final String mPath; 40 41 public MediaPlayerDataSource(Context context, Uri intentUri) { 42 mContext = context; 43 mUri = intentUri; 44 mPath = null; 45 } 46 47 public MediaPlayerDataSource(String path) { 48 mContext = null; 49 mUri = null; 50 mPath = path; 51 } 52 53 public void setAsSourceFor(MediaPlayer mediaPlayer) throws IOException { 54 if (mContext != null) { 55 mediaPlayer.setDataSource(mContext, mUri); 56 } else { 57 mediaPlayer.setDataSource(mPath); 58 } 59 } 60 61 public void playNative() throws IOException { 62 if (mContext != null) { 63 VariableSpeedNative.playFromContext(mContext, mUri); 64 } else { 65 VariableSpeedNative.playUri(mPath); 66 } 67 } 68 } 69