Skip to content

Commit

Permalink
[TIMOB-24909] iOS: Move Ti.Media.AudioPlayer to AVPlayer (#9732)
Browse files Browse the repository at this point in the history
* [TIMOB-24909] First round of AVPlayer implementation

* More fine-tuning, new API's

* Use ARC, fix a bunch of issues

* Handle "stopping" state properly again

* Move constants to Ti.Media namespace to fix parity

* Attempt to create unit tests

* Fix Android indentation / linting

* Fix possible leaks, conform to static analyser

* Fix Android format

* FIx up project structure

* Update AudioPlayer.yml

* Update Media.yml

* Update ti.media.audioplayer.test.js

* Fix "stopped" state, fix deprecation version of old constants

* Add "metadata" event

* Update ti.media.audioplayer.test.js

* Fix version usages, fix playback states

* Update ti.media.audioplayer.test.js

* Make error more descriptive, fix unit-test

* Update ti.media.audioplayer.test.js

* Add missing AUDIO_STATE_INITIALIZED constant, return url as string

* Update ti.media.audioplayer.test.js

* More parity between Android and iOS

* Fix linting

* Fix Android linting

* Fix build error

* Update docs, start improving tests

* Address review comments, fix linting in unit tests

* Update ti.media.audioplayer.test.js
  • Loading branch information
hansemannn committed Jul 28, 2018
1 parent 8deb377 commit e05931f
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 2,631 deletions.
Expand Up @@ -183,20 +183,29 @@ public boolean isPaused()
return false;
}

// An alias for play so that
@Kroll.method
public void start()
{
play();
TiSound s = getSound();
if (s != null) {
s.play();
}
}

@Kroll.method
public void restart()
{
stop();
start();
}

@Kroll.method
public void play()
{
TiSound s = getSound();
if (s != null) {
s.play();
}
Log.w(
TAG,
"The \"play()\" method has been deprecated in favor of the cross-platform \"start()\" method in Titanium 7.4.0.");
start();
}

@Kroll.method
Expand Down Expand Up @@ -243,6 +252,31 @@ public int getAudioSessionId()
return 0;
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public boolean getMuted()
// clang-format on
{
TiSound s = getSound();
if (s != null) {
return s.isMuted();
}
return false;
}

// clang-format off
@Kroll.method
@Kroll.setProperty
public void setMuted(boolean muted)
// clang-format on
{
TiSound s = getSound();
if (s != null) {
s.setMuted(muted);
}
}

// clang-format off
@Kroll.method
@Kroll.getProperty
Expand Down
Expand Up @@ -185,6 +185,27 @@ public class MediaModule extends KrollModule implements Handler.Callback
@Kroll.constant
public static final int CAMERA_FLASH_AUTO = 2;

@Kroll.constant
public static final int AUDIO_STATE_BUFFERING = 0; // current playback is in the buffering from the network state
@Kroll.constant
public static final int AUDIO_STATE_INITIALIZED = 1; // current playback is in the initialization state
@Kroll.constant
public static final int AUDIO_STATE_PAUSED = 2; // current playback is in the paused state
@Kroll.constant
public static final int AUDIO_STATE_PLAYING = 3; // current playback is in the playing state
@Kroll.constant
public static final int AUDIO_STATE_STARTING = 4; // current playback is in the starting playback state
@Kroll.constant
public static final int AUDIO_STATE_STOPPED = 5; // current playback is in the stopped state
@Kroll.constant
public static final int AUDIO_STATE_STOPPING = 6; // current playback is in the stopping state
@Kroll.constant
public static final int AUDIO_STATE_WAITING_FOR_DATA =
7; // current playback is in the waiting for audio data from the network state
@Kroll.constant
public static final int AUDIO_STATE_WAITING_FOR_QUEUE =
8; // current playback is in the waiting for audio data to fill the queue state

private static String mediaType = MEDIA_TYPE_PHOTO;
private static String extension = ".jpg";
private TiTempFileHelper tempFileHelper;
Expand Down
Expand Up @@ -426,6 +426,22 @@ public int getDuration()
return duration;
}

public boolean isMuted()
{
AudioManager audioManager =
(AudioManager) TiApplication.getInstance().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);

return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
}

public void setMuted(boolean muted)
{
if (mp != null) {
float scale = muted ? 0.0f : 1.0f;
mp.setVolume(scale, scale);
}
}

public int getTime()
{
int time = 0;
Expand Down

0 comments on commit e05931f

Please sign in to comment.