1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 package org.mozilla.gecko.media; 6 7 import android.support.annotation.NonNull; 8 import android.util.Log; 9 10 import java.util.ArrayList; 11 12 public final class GeckoPlayerFactory { 13 public static final ArrayList<BaseHlsPlayer> sPlayerList = new ArrayList<BaseHlsPlayer>(); 14 getPlayer()15 synchronized static BaseHlsPlayer getPlayer() { 16 try { 17 final Class<?> cls = Class.forName("org.mozilla.gecko.media.GeckoHlsPlayer"); 18 BaseHlsPlayer player = (BaseHlsPlayer) cls.newInstance(); 19 sPlayerList.add(player); 20 return player; 21 } catch (Exception e) { 22 Log.e("GeckoPlayerFactory", "Class GeckoHlsPlayer not found or failed to create", e); 23 } 24 return null; 25 } 26 getPlayer(final int id)27 synchronized static BaseHlsPlayer getPlayer(final int id) { 28 for (BaseHlsPlayer player : sPlayerList) { 29 if (player.getId() == id) { 30 return player; 31 } 32 } 33 Log.w("GeckoPlayerFactory", "No player found with id : " + id); 34 return null; 35 } 36 removePlayer(final @NonNull BaseHlsPlayer player)37 synchronized static void removePlayer(final @NonNull BaseHlsPlayer player) { 38 int index = sPlayerList.indexOf(player); 39 if (index >= 0) { 40 sPlayerList.remove(player); 41 Log.d("GeckoPlayerFactory", "HlsPlayer with id(" + player.getId() + ") is removed."); 42 } 43 } 44 } 45