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-26334] iOS: Fix some Ti.Media.AudioPlayer related bugs #10285

Merged
merged 9 commits into from
Oct 2, 2018
3 changes: 3 additions & 0 deletions iphone/Classes/TiMediaAudioPlayerProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ - (NSNumber *)duration
// Convert duration to milliseconds (parity with progress/Android)
_duration = (int)(CMTimeGetSeconds([[[self player] currentItem] duration]) * 1000);
}

return NUMDOUBLE(_duration);
}

- (NSNumber *)paused
Expand Down Expand Up @@ -416,6 +418,7 @@ - (void)removeNotificationObserver

[[[self player] currentItem] removeObserver:self forKeyPath:@"playbackBufferEmpty"];
[[[self player] currentItem] removeObserver:self forKeyPath:@"playbackBufferFull"];
[[[self player] currentItem] removeObserver:self forKeyPath:@"timedMetadata"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
Expand Down
4 changes: 2 additions & 2 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4007,7 +4007,7 @@ iOSBuilder.prototype.writeInfoPlist = function writeInfoPlist() {
i18nLaunchScreens[path.basename(p)] = 1;
});

[ {
[{
orientation: 'Portrait',
'minimum-system-version': '12.0',
name: 'Default-Portrait',
Expand Down Expand Up @@ -4109,7 +4109,7 @@ iOSBuilder.prototype.writeInfoPlist = function writeInfoPlist() {
name: 'Default-Landscape',
scale: [ '2x', '1x' ],
size: '{768, 1024}'
} ].forEach(function (asset) {
}].forEach(function (asset) {
asset.scale.some(function (scale) {
let key;
const basefilename = asset.name + (asset.subtype ? '-' + asset.subtype : ''),
Expand Down
61 changes: 61 additions & 0 deletions tests/Resources/ti.media.audioplayer.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.Media', function () {
it('#createAudioPlayer()', function () {
should(Ti.Media.createAudioPlayer).be.a.Function;
});
});

describe('Titanium.Media.AudioPlayer', function () {
var audioPlayer;

beforeEach(function () {
audioPlayer = Ti.Media.createAudioPlayer({ url: '/sample.mp3' });
});

afterEach(function () {
audioPlayer = null;
});

// Updated existing test-case, please replace with old one
it('.url', function (finish) {
should(audioPlayer.url).be.a.String;
should(audioPlayer.getUrl).be.a.Function;
should(audioPlayer.setUrl).be.a.Function;
should(audioPlayer.url).eql(audioPlayer.getUrl());

// Re-set URL to test TIMOB-26334, this should not crash
try {
audioPlayer.url = '/sample.mp3';
finish();
} catch (e) {
finish(e);
}
});

it('.duration', function (finish) {
this.timeout(2000);
audioPlayer.start();

setTimeout(function () {
try {
should(audioPlayer.duration).be.a.Number;
// give a tiny bit of fudge room here. iOS and Android differ by 5ms on this file
should(audioPlayer.duration).be.within(45250, 45500); // 45 seconds. iOS gives us 45322, Android gives 45327
finish();
} catch (e) {
finish(e);
}
}, 1000);
});
});