Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-9065: Android: Sound - Remote URL does not play #5060

Merged
merged 1 commit into from
Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public class SoundProxy extends KrollProxy
{
private static final String TAG = "SoundProxy";

@Kroll.constant public static final int STATE_BUFFERING = TiSound.STATE_BUFFERING;
@Kroll.constant public static final int STATE_INITIALIZED = TiSound.STATE_INITIALIZED;
@Kroll.constant public static final int STATE_PAUSED = TiSound.STATE_PAUSED;
@Kroll.constant public static final int STATE_PLAYING = TiSound.STATE_PLAYING;
@Kroll.constant public static final int STATE_STARTING = TiSound.STATE_STARTING;
@Kroll.constant public static final int STATE_STOPPED = TiSound.STATE_STOPPED;
@Kroll.constant public static final int STATE_STOPPING = TiSound.STATE_STOPPING;
@Kroll.constant public static final int STATE_WAITING_FOR_DATA = TiSound.STATE_WAITING_FOR_DATA;
@Kroll.constant public static final int STATE_WAITING_FOR_QUEUE = TiSound.STATE_WAITING_FOR_QUEUE;

protected TiSound snd;
private boolean windowFocused;
private boolean resumeInOnWindowFocusChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ public void onPrepared(MediaPlayer mp)
{
mp.setOnPreparedListener(null);
mp.seekTo(0);
playPending = false;
if (!stopPending && !pausePending) {
startPlaying();
}
playPending = false;
pausePending = false;
stopPending = false;
}
Expand All @@ -254,7 +254,7 @@ public void onPrepared(MediaPlayer mp)
public void reset()
{
try {
if (mp != null) {
if (mp != null && (mp.isPlaying() || isPaused())) {
stopProgressTimer();

setState(STATE_STOPPING);
Expand Down Expand Up @@ -327,8 +327,8 @@ public void setVolume(float volume)
public int getDuration()
{
int duration = 0;
if (mp != null) {
duration = mp.getDuration();
if (mp != null && !playPending) {
duration = mp.getDuration(); // Can only get duration after the media player is initialized.
}
return duration;
}
Expand Down Expand Up @@ -595,7 +595,7 @@ public void propertiesChanged(List<KrollPropertyChange> changes, KrollProxy prox
private void startPlaying()
{
if (mp != null) {
if (!isPlaying()) {
if (!isPlaying() && !playPending) {
Log.d(TAG, "audio is not playing, starting.", Log.DEBUG_MODE);
Log.d(TAG, "Play: Volume set to " + volume, Log.DEBUG_MODE);
mp.start();
Expand All @@ -615,6 +615,7 @@ public void onPrepared(MediaPlayer mp)
if (proxy.hasProperty(TiC.PROPERTY_TIME)) {
setTime(TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_TIME)));
}
playPending = false;
if (!pausePending && !stopPending) {
try {
startPlaying();
Expand All @@ -623,7 +624,6 @@ public void onPrepared(MediaPlayer mp)
reset();
}
}
playPending = false;
pausePending = false;
stopPending = false;
}
Expand Down
81 changes: 81 additions & 0 deletions apidoc/Titanium/Media/Sound.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ methods:
summary: Stops playing the audio and resets the playback position to the beginning of the clip.

events:
- name: change
summary: Fired when the state of the playback changes.
description: |
This event can be generated by programmatic events, such as pausing or stopping the audio,
and also by external events, such as the current state of network buffering.
since: "3.2.0"
platforms: [android]
properties:
- name: state
summary: |
Current state of playback, specified using one of the `STATE` constants defined on this object.
type: Number
- name: description
summary: Text description of the state of playback.

- name: complete
summary: Fired when the audio has finished playing.
properties:
Expand Down Expand Up @@ -141,6 +156,69 @@ events:
platforms: [iphone, ipad]

properties:
- name: STATE_BUFFERING
summary: Audio data is being buffered from the network.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_INITIALIZED
summary: Audio playback is being initialized.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_PAUSED
summary: Playback is paused.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_PLAYING
summary: Audio playback is active.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_STARTING
summary: Audio playback is starting.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_STOPPED
summary: Audio playback is stopped.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_STOPPING
summary: Audio playback is stopping.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_WAITING_FOR_DATA
summary: Player is waiting for audio data from the network.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: STATE_WAITING_FOR_QUEUE
summary: Player is waiting for audio data to fill the queue.
type: Number
permission: read-only
since: "3.2.0"
platforms: [android]

- name: allowBackground
summary: Determines whether the audio should continue playing even when its activity is paused.
since: "1.3.0"
Expand All @@ -156,6 +234,9 @@ properties:
On iOS, playback time is reported in seconds.

On Android and Tizen, time is reported in milliseconds.

Android note: Starting from Titanium 3.2.0, the remote audio plays asynchronously. The duration
can only be fetched after the audio is initialized (refer to <Titanium.Media.Sound.STATE_INITIALIZED>).
type: Number
permission: read-only
exclude-platforms: [blackberry]
Expand Down