Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6941] Android: Media - AudioPlayer progress event units of measure not consistent between 1.7.X and 1.8.0.X

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2012-02-03T14:29:49.000+0000
Affected Version/sRelease 1.7.5, Release 1.8.0.1
Fix Version/sn/a
ComponentsAndroid
Labelslook1, regression
ReporterPaul Dowsett
AssigneeHieu Pham
Created2011-12-30T05:26:08.000+0000
Updated2017-03-13T22:14:12.000+0000

Description

Problem

AudioPlayer progress event units of measure not consistent between 1.7.X and 1.8.0.X. On 1.7.5 units are seconds On 1.8.0.1 units are milliseconds Is this a regression, or intended? The APIDocs at [Titanium.Media.AudioPlayer.progress](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.AudioPlayer.progress-property.html) do not explain which units are intended. Note: this needs to be tested on iOS to ensure parity.

Logs

The following logs are output when the test case below is run
I/TiAPI   ( 5265): EAC LOGGING: Progress: 1121
I/TiAPI   ( 5265): EAC LOGGING: Progress: 2113
I/TiAPI   ( 5265): EAC LOGGING: Progress: 3104
I/TiAPI   ( 5265): EAC LOGGING: Progress: 4122
I/TiAPI   ( 5265): EAC LOGGING: Progress: 5113
I/TiAPI   ( 5945): EAC LOGGING: Progress: 1043
I/TiAPI   ( 5945): EAC LOGGING: Progress: 2061
I/TiAPI   ( 5945): EAC LOGGING: Progress: 3052
I/TiAPI   ( 5945): EAC LOGGING: Progress: 4044
I/TiAPI   ( 5945): EAC LOGGING: Progress: 5035
I/TiAPI   ( 5614): (kroll$1: app://app.js) [1005,12541] EAC LOGGING: Progress: 2.087
I/TiAPI   ( 5614): (kroll$1: app://app.js) [998,13539] EAC LOGGING: Progress: 3.078
I/TiAPI   ( 5614): (kroll$1: app://app.js) [1009,14548] EAC LOGGING: Progress: 4.07
I/TiAPI   ( 5614): (kroll$1: app://app.js) [996,15544] EAC LOGGING: Progress: 5.061
I/TiAPI   ( 5614): (kroll$1: app://app.js) [1000,16544] EAC LOGGING: Progress: 6.079

Test case

This code was adapted from KS [sound_remote.js](https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/sound_remote.js).
var audiofile = 'HTTP://www.host.com/path/to/file.mp3'; // see restricted comments for example
var win = Ti.UI.createWindow({
  backgroundColor: 'white',
  fullscreen: false,
  layout:'vertical'
});

win.open();

var url = Titanium.UI.createTextField({
  value:audiofile,
  color:'#336699',
  returnKeyType:Titanium.UI.RETURNKEY_GO,
  keyboardType:Titanium.UI.KEYBOARD_URL,
  hintText:'url',
  textAlign:'left',
  clearOnEdit:false, // this set to true was clearing the field on launch
  height:35,
  top:30,
  width:300,
  borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});

var streamButton = Titanium.UI.createButton({
  title:'Start Streaming',
  top:30,
  width:200,
  height:40
});

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

var progressLabel = Titanium.UI.createLabel({
  text:'Time Played: Not Started',
  top:30,
  left:10,
  height:40,
  width:300,
  color:'#555',
  textAlignment:'center'
});

var stateLabel = Titanium.UI.createLabel({
  text:'State: Not Started',
  top:30,
  left:10,
  width:300,
  height:40,
  color:'#555'
});

var streamSize1 = Ti.UI.createButton({
  title:'Small buffer',
  top:30,
  left:10,
  width:100,
  height:40
});
var streamSize2 = Ti.UI.createButton({
  title:'Default buffer',
  top:30,
  left:110,
  width:100,
  height:40
});
var streamSize3 = Ti.UI.createButton({
  title:'Large buffer',
  top:30,
  right:10,
  width:100,
  height:40
});

win.add(url);
win.add(streamButton);
win.add(pauseButton);
win.add(progressLabel);
win.add(stateLabel);

if (Ti.Platform.name != 'android') {
  win.add(streamSize1);
  win.add(streamSize2);
  win.add(streamSize3);
}

var streamer = Ti.Media.createAudioPlayer();

streamButton.addEventListener('click',function()
{
  if (streamButton.title == 'Stop Stream')
  {
    progressLabel.text = 'Stopped';
    streamer.stop();
    pauseButton.enabled = false;
    streamSize1.enabled = true;
    streamSize2.enabled = true;
    streamSize3.enabled = true;
    pauseButton.title = 'Pause Streaming';
    streamButton.title = "Start Streaming";
  }
  else
  {
    progressLabel.text = 'Starting ...';
    streamer.url = url.value;
    streamer.start();
    pauseButton.enabled = true;
    streamSize1.enabled = false;
    streamSize2.enabled = false;
    streamSize3.enabled = false;

    pauseButton.title = 'Pause Streaming';
    streamButton.title = "Stop Stream";
  }
});

pauseButton.addEventListener('click', function()
{
  streamer.pause();
  if (streamer.paused) {
    pauseButton.title = 'Unpause Streaming';
  }
  else {
    pauseButton.title = 'Pause Streaming';
  }
});

streamSize1.addEventListener('click', function()
{
  streamer.bufferSize = 512;
  Ti.API.log('Set streamer buffer size to ' + streamer.bufferSize);
});
streamSize2.addEventListener('click', function()
{
  streamer.bufferSize = 2048;
  Ti.API.log('Set streamer buffer size to ' + streamer.bufferSize);
});
streamSize3.addEventListener('click', function()
{
  streamer.bufferSize = 4096;
  Ti.API.log('Set streamer buffer size to ' + streamer.bufferSize);
});

streamer.addEventListener('progress',function(e)
{
  Ti.API.info('EAC LOGGING: Progress: '+e.progress);
  progressLabel.text = 'Time Played: ' + Math.round(e.progress) + ' seconds';
});

streamer.addEventListener('change',function(e)
{
  stateLabel.text = 'State: '+e.description +' ('+e.state+')';
  if(e.description == "stopped") {
    progressLabel.text = 'Stopped';
    pauseButton.enabled = false;
    pauseButton.title = 'Pause Streaming';
    streamButton.title = "Start Streaming";
  }
});

// save off current idle timer state
var idleTimer = Ti.App.idleTimerDisabled;

// while we're in this window don't let the app shutdown
// when the screen is idle
Ti.App.idleTimerDisabled = true;

win.addEventListener('close',function()
{
  Ti.API.info("window was closed, idleTimer reset to = "+idleTimer);

  // restore previous idle state when closed
  Ti.App.idleTimerDisabled = idleTimer;
});

Comments

  1. Hieu Pham 2012-02-03

    Discussed with Blain and ms is the correct unit for MediaPlayer. Closing bug as invalid
  2. Lee Morris 2017-03-13

    Closing ticket as invalid.

JSON Source