| GitHub Issue | n/a |
| Type | New Feature |
| Priority | Medium |
| Status | Reopened |
| Resolution | Unresolved |
| Affected Version/s | Release 7.5.0 |
| Fix Version/s | 2013 Sprint 21, 2013 Sprint 21 API, Release 3.2.0 |
| Components | iOS |
| Labels | module_media, qe-closed-3.2.0, qe-testadded, regression |
| Reporter | Shashi Jain |
| Assignee | Unknown |
| Created | 2012-10-06T22:45:53.000+0000 |
| Updated | 2018-11-16T12:02:14.000+0000 |
When using Titanium.Media.AUDIO_SESSION_MODE_PLAY_AND_RECORD, the audio output is routed to the receiver (the speaker in the earpiece of iPhone). This request would allow you to override this behavior to make the audio play out of the speaker (the speakerphone, located near the doc connector on iPhone).
Made a Pull Request on Github for this.
Please could you link the pull request? Thanks.
https://github.com/appcelerator/titanium_mobile/pull/3121
PR merged Created TIDOC-1291 for documentation
Closing ticket as fixed. While setting Ti.Media.audioSessionMode to Ti.Media.AUDIO_SESSION_MODE_PLAY_AND_RECORD, verified I was able to route the audio output to either the phone's receiver or to the phone's internal speaker. Tested on: Appcelerator Studio, build: 3.2.0.201312091648 SDK build: 3.2.0.v20131210112451 CLI: 3.2.0-cr Alloy: 1.3.0-cr Xcode: 5.0.2 Device: iphone 5 (7.0.2), iphone 4s (6.0.1) *Note:* Below is the code I used to verify this ticket. And, I attached the missing media files that the below code uses.
var window = Ti.UI.createWindow({ backgroundColor: 'white' }); var scrollView = Ti.UI.createScrollView({ contentWidth : 'auto', contentHeight : 'auto', showVerticalScrollIndicator : true, layout : 'vertical', height : '85%', width : Ti.UI.FILL }); Ti.Media.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAY_AND_RECORD; var isToSpeaker = false; var toggleOverride = Ti.UI.createButton({ title:'Toggle Audio Output' }); toggleOverride.addEventListener('click', function(){ if(isToSpeaker){ // if routed to speaker, then route to receiver of phone Ti.Media.setOverrideAudioRoute(Ti.Media.AUDIO_SESSION_OVERRIDE_ROUTE_NONE); alert('audio routed to the phone\'s receiver'); } else { Ti.Media.setOverrideAudioRoute(Ti.Media.AUDIO_SESSION_OVERRIDE_ROUTE_SPEAKER); alert('audio routed to the phone\'s internal speaker'); } isToSpeaker = !isToSpeaker; }); scrollView.add(toggleOverride); // Video player volume test scrollView.add(Ti.UI.createLabel({ text : 'Video Player', height : Ti.UI.SIZE, width : Ti.UI.SIZE, color : 'black' })); var videoPlayer = Titanium.Media.createVideoPlayer({ height : 300, width : 300, mediaControlStyle : Ti.Media.VIDEO_CONTROL_DEFAULT, scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT, url : 'movie.mp4', volume : 0.0 }); scrollView.add(videoPlayer); scrollView.add(createVolumeControl(videoPlayer)); // Sound volume test scrollView.add(Ti.UI.createLabel({ text : 'Sound Player', height : Ti.UI.SIZE, width : Ti.UI.SIZE, color : 'black', top : 20 })); var sound = Ti.Media.createSound({ url : 'comic001.wav' }); scrollView.add(createVolumeControl(sound)); var playSoundButton = Ti.UI.createButton({ title : "Play Sound", height : Ti.UI.SIZE, width : Ti.UI.SIZE }); playSoundButton.addEventListener('click', function() { if (sound.isPlaying()) { sound.stop(); playSoundButton.title = 'Play Sound'; } else { sound.play(); playSoundButton.title = 'Stop Sound'; } }); scrollView.add(playSoundButton); // Audio volume test scrollView.add(Ti.UI.createLabel({ text : 'Audio Player', height : Ti.UI.SIZE, width : Ti.UI.SIZE, color : 'black', top : 20 })); // TIMOB-9409: iOS cannot play local mp3 files var audio = Ti.Media.createAudioPlayer({ url : 'http://appcelerator.qe.test.data.s3.amazonaws.com/timob8992Music.mp3', volume : 0.5 }); scrollView.add(createVolumeControl(audio)); var playAudioButton = Ti.UI.createButton({ title : "Play Audio", height : Ti.UI.SIZE, width : Ti.UI.SIZE }); playAudioButton.addEventListener('click', function() { if (audio.playing) { audio.stop(); playAudioButton.title = 'Play Audio'; } else { audio.start(); playAudioButton.title = 'Stop Audio'; } }); scrollView.add(playAudioButton); function createVolumeControl(player) { var slider = Ti.UI.createSlider({ value : player.volume * 100, min : 0, max : 100, width : Ti.UI.FILL }); slider.addEventListener('change', function(e) { player.volume = e.value / 100; }); return slider; }; window.add(scrollView); window.open();