PageRenderTime 308ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/java/jd-gui/android/media/AsyncPlayer.java

https://bitbucket.org/chaos_rom/miui_frameworks
Java | 189 lines | 170 code | 15 blank | 4 comment | 26 complexity | af37e494909101b4aebdf809220db524 MD5 | raw file
  1. package android.media;
  2. import android.content.Context;
  3. import android.net.Uri;
  4. import android.os.PowerManager;
  5. import android.os.PowerManager.WakeLock;
  6. import android.os.SystemClock;
  7. import android.util.Log;
  8. import java.util.LinkedList;
  9. public class AsyncPlayer
  10. {
  11. private static final int PLAY = 1;
  12. private static final int STOP = 2;
  13. private static final boolean mDebug;
  14. private final LinkedList<Command> mCmdQueue = new LinkedList();
  15. private MediaPlayer mPlayer;
  16. private int mState = 2;
  17. private String mTag;
  18. private Thread mThread;
  19. private PowerManager.WakeLock mWakeLock;
  20. public AsyncPlayer(String paramString)
  21. {
  22. if (paramString != null);
  23. for (this.mTag = paramString; ; this.mTag = "AsyncPlayer")
  24. return;
  25. }
  26. private void acquireWakeLock()
  27. {
  28. if (this.mWakeLock != null)
  29. this.mWakeLock.acquire();
  30. }
  31. private void enqueueLocked(Command paramCommand)
  32. {
  33. this.mCmdQueue.add(paramCommand);
  34. if (this.mThread == null)
  35. {
  36. acquireWakeLock();
  37. this.mThread = new Thread();
  38. this.mThread.start();
  39. }
  40. }
  41. private void releaseWakeLock()
  42. {
  43. if (this.mWakeLock != null)
  44. this.mWakeLock.release();
  45. }
  46. private void startSound(Command paramCommand)
  47. {
  48. try
  49. {
  50. MediaPlayer localMediaPlayer = new MediaPlayer();
  51. localMediaPlayer.setAudioStreamType(paramCommand.stream);
  52. localMediaPlayer.setDataSource(paramCommand.context, paramCommand.uri);
  53. localMediaPlayer.setLooping(paramCommand.looping);
  54. localMediaPlayer.prepare();
  55. localMediaPlayer.start();
  56. if (this.mPlayer != null)
  57. this.mPlayer.release();
  58. this.mPlayer = localMediaPlayer;
  59. long l = SystemClock.uptimeMillis() - paramCommand.requestTime;
  60. if (l > 1000L)
  61. Log.w(this.mTag, "Notification sound delayed by " + l + "msecs");
  62. return;
  63. }
  64. catch (Exception localException)
  65. {
  66. while (true)
  67. Log.w(this.mTag, "error loading sound for " + paramCommand.uri, localException);
  68. }
  69. }
  70. public void play(Context paramContext, Uri paramUri, boolean paramBoolean, int paramInt)
  71. {
  72. Command localCommand = new Command(null);
  73. localCommand.requestTime = SystemClock.uptimeMillis();
  74. localCommand.code = 1;
  75. localCommand.context = paramContext;
  76. localCommand.uri = paramUri;
  77. localCommand.looping = paramBoolean;
  78. localCommand.stream = paramInt;
  79. synchronized (this.mCmdQueue)
  80. {
  81. enqueueLocked(localCommand);
  82. this.mState = 1;
  83. return;
  84. }
  85. }
  86. public void setUsesWakeLock(Context paramContext)
  87. {
  88. if ((this.mWakeLock != null) || (this.mThread != null))
  89. throw new RuntimeException("assertion failed mWakeLock=" + this.mWakeLock + " mThread=" + this.mThread);
  90. this.mWakeLock = ((PowerManager)paramContext.getSystemService("power")).newWakeLock(1, this.mTag);
  91. }
  92. public void stop()
  93. {
  94. synchronized (this.mCmdQueue)
  95. {
  96. if (this.mState != 2)
  97. {
  98. Command localCommand = new Command(null);
  99. localCommand.requestTime = SystemClock.uptimeMillis();
  100. localCommand.code = 2;
  101. enqueueLocked(localCommand);
  102. this.mState = 2;
  103. }
  104. return;
  105. }
  106. }
  107. private final class Thread extends Thread
  108. {
  109. Thread()
  110. {
  111. super();
  112. }
  113. public void run()
  114. {
  115. while (true)
  116. {
  117. AsyncPlayer.Command localCommand;
  118. synchronized (AsyncPlayer.this.mCmdQueue)
  119. {
  120. localCommand = (AsyncPlayer.Command)AsyncPlayer.this.mCmdQueue.removeFirst();
  121. switch (localCommand.code)
  122. {
  123. default:
  124. case 1:
  125. case 2:
  126. }
  127. }
  128. synchronized (AsyncPlayer.this.mCmdQueue)
  129. {
  130. while (AsyncPlayer.this.mCmdQueue.size() == 0)
  131. {
  132. AsyncPlayer.access$402(AsyncPlayer.this, null);
  133. AsyncPlayer.this.releaseWakeLock();
  134. return;
  135. localObject1 = finally;
  136. throw localObject1;
  137. AsyncPlayer.this.startSound(localCommand);
  138. continue;
  139. if (AsyncPlayer.this.mPlayer != null)
  140. {
  141. long l = SystemClock.uptimeMillis() - localCommand.requestTime;
  142. if (l > 1000L)
  143. Log.w(AsyncPlayer.this.mTag, "Notification stop delayed by " + l + "msecs");
  144. AsyncPlayer.this.mPlayer.stop();
  145. AsyncPlayer.this.mPlayer.release();
  146. AsyncPlayer.access$302(AsyncPlayer.this, null);
  147. }
  148. else
  149. {
  150. Log.w(AsyncPlayer.this.mTag, "STOP command without a player");
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. private static final class Command
  158. {
  159. int code;
  160. Context context;
  161. boolean looping;
  162. long requestTime;
  163. int stream;
  164. Uri uri;
  165. public String toString()
  166. {
  167. return "{ code=" + this.code + " looping=" + this.looping + " stream=" + this.stream + " uri=" + this.uri + " }";
  168. }
  169. }
  170. }
  171. /* Location: /home/lithium/miui/chameleon/2.11.16/framework_dex2jar.jar
  172. * Qualified Name: android.media.AsyncPlayer
  173. * JD-Core Version: 0.6.2
  174. */