Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8992] Ti API: Create consistent volume properties for all player types.

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-05-24T15:01:25.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 2.1.0, Sprint 2012-10 API
ComponentsTiAPI
Labelsapi, module_media, qe-testadded
ReporterVishal Duggal
AssigneeVishal Duggal
Created2012-05-04T09:33:42.000+0000
Updated2012-10-17T22:06:03.000+0000

Description

Right now only the Sound API has the ability to set volume. There have been numerous requests to provide the same functionality for AudioPlayer, VideoPlayer and Recording.

Media Player Volume Test Case

function createVolumeControl(player) {
	var slider = Ti.UI.createSlider({
		value: player.volume * 100,
		min: 0,
		max: 100,
		width: 500
	});

	slider.addEventListener('change', function(e) {
		player.volume = e.value/100;
	});

	return slider;
}

function createSoundPlayerTab() {
	var win = Ti.UI.createWindow({layout: 'vertical'});
	
	var sound = Ti.Media.createSound({url:'sound.wav'});

	win.add(createVolumeControl(sound));
	
	var playSoundButton = Ti.UI.createButton({
		title: "Play Sound",
		height: 100,
		width: 200
	});
	playSoundButton.addEventListener('click', function() {
		sound.play();
	});
	win.add(playSoundButton);

	return Ti.UI.createTab({
		title: "Sound Player",
		window: win
	});
}

function createAudioPlayerTab() {
	var win = Ti.UI.createWindow({layout: 'vertical'});

	var audio = Ti.Media.createAudioPlayer({url: 'music.mp3', volume: 0.5});

	win.add(createVolumeControl(audio));

	var playAudioButton = Ti.UI.createButton({
		title: "Play Audio",
		height: 100,
		width: 200
	});
	playAudioButton.addEventListener('click', function() {
		audio.play();
	});
	win.add(playAudioButton);

	return Ti.UI.createTab({
		title: "Audio Player",
		window: win
	});
}

function createVideoPlayerTab() {
	var win = Ti.UI.createWindow({layout: 'vertical'});

	var videoPlayer = Titanium.Media.createVideoPlayer({
	    height : 300,
	    width : 300,
	    mediaControlStyle : Titanium.Media.VIDEO_CONTROL_NONE,
	    scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
	    url: 'movie.mp4',
	    volume: 0.0
	});
	win.add(videoPlayer);

	win.add(createVolumeControl(videoPlayer));

	return Ti.UI.createTab({
		title: "Video Player",
		window: win
	});
}

var tabGroup = Ti.UI.createTabGroup();
tabGroup.addTab(createSoundPlayerTab());
tabGroup.addTab(createAudioPlayerTab());
tabGroup.addTab(createVideoPlayerTab());
tabGroup.open();
1. Create an application with the above source code. 2. Be sure to place media files in your Resources folder (ex: music.mp4, sound.wav) 3. Go through each tab which includes a test for each media player type. 4. Start the media by clicking the button. Try adjusting the volume. It should change as you move the slider. 5. Repeat for the next tab and so forth.

Comments

  1. Wilson Luu 2012-06-06

    Closing feature. Was able to verify volume feature works on: SDK build: 2.1.0.v20120605190238 Titanium Studio, build: 2.1.0.201206051612 Runtime: v8 xcode: 4.3.2 Device: iphone 4s verizon (5.0.1), droid 1 (2.2.3)

JSON Source