1 /* 2 * Copyright 2020 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 package org.hyphonate.megaaudio.player; 17 18 import android.media.AudioDeviceInfo; 19 20 import org.hyphonate.megaaudio.common.BuilderBase; 21 22 public class PlayerBuilder extends BuilderBase { 23 private AudioSourceProvider mSourceProvider; 24 PlayerBuilder()25 public PlayerBuilder() { 26 27 } 28 setPlayerType(int playerType)29 public PlayerBuilder setPlayerType(int playerType) { 30 mType = playerType; 31 return this; 32 } 33 setSourceProvider(AudioSourceProvider sourceProvider)34 public PlayerBuilder setSourceProvider(AudioSourceProvider sourceProvider) { 35 mSourceProvider = sourceProvider; 36 return this; 37 } 38 build()39 public Player build() throws BadStateException { 40 if (mSourceProvider == null) { 41 throw new BadStateException(); 42 } 43 44 Player player = null; 45 int playerType = mType & TYPE_MASK; 46 switch (playerType) { 47 case TYPE_NONE: 48 // NOP 49 break; 50 51 case TYPE_JAVA: 52 player = new JavaPlayer(mSourceProvider); 53 break; 54 55 case TYPE_OBOE:{ 56 int playerSubType = mType & SUB_TYPE_MASK; 57 player = new OboePlayer(mSourceProvider, playerSubType); 58 } 59 break; 60 61 default: 62 throw new BadStateException(); 63 } 64 65 return player; 66 } 67 68 public class BadStateException extends Throwable { 69 70 } 71 } 72