Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13397] iOS: Add ability to override audio routes

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusReopened
ResolutionUnresolved
Affected Version/sRelease 7.5.0
Fix Version/s2013 Sprint 21, 2013 Sprint 21 API, Release 3.2.0
ComponentsiOS
Labelsmodule_media, qe-closed-3.2.0, qe-testadded, regression
ReporterShashi Jain
AssigneeUnknown
Created2012-10-06T22:45:53.000+0000
Updated2018-11-16T12:02:14.000+0000

Description

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).

Attachments

FileDateSize
comic001.wav2013-12-11T01:29:33.000+0000117414
movie.mp42013-12-11T01:29:33.000+00002549211

Comments

  1. Shashi Jain 2012-10-06

    Made a Pull Request on Github for this.
  2. Daniel Sefton 2012-11-28

    Please could you link the pull request? Thanks.
  3. Shashi Jain 2012-11-28

    https://github.com/appcelerator/titanium_mobile/pull/3121
  4. Vishal Duggal 2013-10-07

    PR merged Created TIDOC-1291 for documentation
  5. Wilson Luu 2013-12-11

    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();
       

JSON Source