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-16102] iOS: AudioPlayer progress event not firing #7974

Closed
wants to merge 2 commits into from

Conversation

AngelkPetkov
Copy link
Contributor

{
[timer invalidate];
RELEASE_TO_NIL(timer);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

@@ -50,15 +50,19 @@ -(void)_listenerAdded:(NSString *)type count:(int)count
{
if (count == 1 && [type isEqualToString:@"progress"])
{
progress = YES;
timer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES] retain];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause problems when the user creates different progress event listener. That's why it was in the initial creation only. Please test different event listeners and try to come up with a solution that can handle different event listeners as well (like before).

@AngelkPetkov
Copy link
Contributor Author

Added Validation so the timer is only initialized once, this will allow you to have multiple progress events like so :
Titanium.UI.setBackgroundColor('#fff');
var win = Ti.UI.createWindow();

var audioPlayer = Ti.Media.createAudioPlayer({
    url : '/Users/Angel/Music/iTunes/iTunes\ Media/Music/Trap\ Nation/Unknown\ Album/SNBRN\ -\ Gangsta\ Walk\ \(feat.\ Nate\ Dogg\)\ \(JayKode\ Remix\).mp3' //Add local or remote file
});

var button = Titanium.UI.createButton({
   title: 'Start/Stop',
   top: 10,
   width: 100,
   height: 50
});
var playing = false;
button.addEventListener('click',function(e)
{
    if (playing != true) { 
        audioPlayer.start();
    } else {
        audioPlayer.pause();
    }
    playing = !playing;
});


audioPlayer.start();


audioPlayer.addEventListener('progress', function(a) {
    Ti.API.info("Cool beans");
});


audioPlayer.addEventListener('progress', function(e) {
    Ti.API.info("Hello Mundo");
    // alert('EAC LOGGING: Progress: ' + e.progress);
});


win.add(button);
win.open();

@hansemannn
Copy link
Collaborator

PR rejected. It only doesn't work in your example because the event listener is placed incorrectly. Placing it before starting the player fixes the issue (which is none, because that's the common way to implement the observer pattern). More info inside the ticket.

@hansemannn hansemannn closed this May 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants