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-23258] Android: Support audioSessionId getters #7989

Merged
merged 2 commits into from May 6, 2016

Conversation

AngelkPetkov
Copy link
Contributor

@AngelkPetkov AngelkPetkov commented May 5, 2016

JIRA

Community PR , FT please.

@ashcoding
Copy link
Contributor

Test Code:

var win = Titanium.UI.createWindow({  
    title:'Audio Test',
    backgroundColor:'#fff',
    layout: 'vertical'
});

var startStopButton = Titanium.UI.createButton({
    title:'Start/Stop Streaming',
    top:10,
    width:200,
    height:40
});

var pauseResumeButton = Titanium.UI.createButton({
    title:'Pause/Resume Streaming',
    top:10,
    width:200,
    height:40,
    enabled:false
});

var getID = Titanium.UI.createButton({
    title:'getId',
    top:10,
    width:200,
    height:40
});

win.add(startStopButton);
win.add(pauseResumeButton);
win.add(getID);

// allowBackground: true on Android allows the 
// player to keep playing when the app is in the 
// background.
var audioPlayer = Ti.Media.createAudioPlayer({ 
    url: 'http://www.noiseaddicts.com/samples_1w72b820/17.mp3',
    allowBackground: true
});           

startStopButton.addEventListener('click',function() {
    // When paused, playing returns false.
    // If both are false, playback is stopped.
    if (audioPlayer.playing || audioPlayer.paused)
    {
        audioPlayer.stop();
        pauseResumeButton.enabled = false;
        if (Ti.Platform.name === 'android')
        { 
            audioPlayer.release();
        }   
    }
    else
    {
        audioPlayer.start();
        pauseResumeButton.enabled = true;
    }
});

pauseResumeButton.addEventListener('click', function() {
    if (audioPlayer.paused) {
        audioPlayer.start();
    }
    else {
        audioPlayer.pause();
    }
});

audioPlayer.addEventListener('progress',function(e) {
    Ti.API.info('Time Played: ' + Math.round(e.progress) + ' milliseconds');
});

audioPlayer.addEventListener('change',function(e)
{
    Ti.API.info('State: ' + e.description + ' (' + e.state + ')');
});

win.addEventListener('close',function() {
    audioPlayer.stop();
    if (Ti.Platform.osname === 'android')
    { 
        audioPlayer.release();
    }
});

getID.addEventListener('click', function() {
    alert("Audio Player Id:"+ audioPlayer.getAudioSessionId());
});


win.open();

Test steps:-

  1. Press GetID. You will get 0.
  2. Press Start streaming.
  3. Press GetID. You will get an ID.
  4. While still streaming, press stop.
  5. Press GetID. You will get 0.

@ashcoding
Copy link
Contributor

ashcoding commented May 6, 2016

@AngelkPetkov we are feature freezing for 5.4.0. This should be fine to be added for 5.4.0. Before that, could you do a few things?

  1. Your PR code alignment is off. Please format the code correctly.
  2. Add documentation.

After that's done, could you get someone to review the documentation and code alignment? I think Hans should be fine with checking it. Once that's done, please merge this.

@ashcoding
Copy link
Contributor

Code functionally tested with the test case above and reviewed as mentioned above. This can be merged (by Hans, Hieu or Angel) once the above comments have been addressed.
@AngelkPetkov please get it in before Friday ends.

@AngelkPetkov AngelkPetkov assigned ashcoding and unassigned hieupham007 May 6, 2016
if (s != null) {
return s.getAudioSessionId();
}
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is off

[TIMOB-23258] Android: Added Documentation
@AngelkPetkov
Copy link
Contributor Author

Made indentation same as the rest of the class and added docs. Thanks Ash!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants