Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24281] iOS: Titanium.Media.openMusicLibrary returns empty items on iOS 10 and 9

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2017-01-20T22:40:09.000+0000
Affected Version/sRelease 6.0.0, Release 6.0.1
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterShuo Liang
AssigneeHans Knöchel
Created2017-01-06T00:52:25.000+0000
Updated2017-01-20T22:40:17.000+0000

Description

Reproduce

1. Create a new projects 2. Add iOS 10 permissions onto your plist on tiapp.xml. 3. Execute this function below:
		Titanium.Media.openMusicLibrary({
			allowMultipleSelections : false,
			mediaTypes : Titanium.Media.MUSIC_MEDIA_TYPE_MUSIC|Titanium.Media.MUSIC_MEDIA_TYPE_ANY_AUDIO,
			success : function(event) {
				// called when media returned from the MusicLibrary
				console.log("Results: " + JSON.stringify(event));
			},
			cancel : function() {
				alert("Aborting ");
			},
			error : function(error) {
				// called when there's an error
				var a = Titanium.UI.createAlertDialog({
					title : 'Music Library'
				});
				if (error.code == Titanium.Media.NO_MUSIC_PLAYER) {
					a.setMessage('Please run this test on device.');
				} else {
					a.setMessage('Unexpected error: ' + error.code);
				}
				a.show();
			}
		});
4. Log the MusicLibraryResponseType on success 5. Launch the app on device only!

Expected Result

The 'items' attribute will be populated with data.

Actual Result

The 'items' attribute will be an empty dictionary. Like:
{"items":[{}],"source":{},"types":1,"code":0,"success":true,"type":"success","representative":{}}

Attachments

FileDateSize
tiapp (1).xml2017-01-06T00:52:24.000+00008288

Comments

  1. Hans Knöchel 2017-01-06

    So it works on master (6.1.0) for me, need to perform 6.0.1.GA device tests. But event.items.length returns 1 for me, the items are just not stringified in the console. I'll get back soon. *EDIT*: Tested with 6.0.1.GA as well, using all kind of configurations (including the one linked here in the tiapp.xml). The items are returned, you can check it by grabbing the title:
       
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       
       var btn = Ti.UI.createButton({
           title: 'Trigger'
       });
       
       btn.addEventListener('click', function() {
           if (Ti.Media.hasMusicLibraryPermissions()) {
               openMusicLibrary();
           } else {
               Ti.Media.requestMusicLibraryPermissions(function(e) {
                   if (!e.success) {
                       alert("No permissions!");
                       return;
                   }
                   openMusicLibrary();
               })
           }
       });
       
       win.add(btn);
       win.open();
       
       function openMusicLibrary() {
           Ti.Media.openMusicLibrary({
       		allowMultipleSelections : true,
       		mediaTypes : Titanium.Media.MUSIC_MEDIA_TYPE_MUSIC | Titanium.Media.MUSIC_MEDIA_TYPE_ANY_AUDIO,
       		success : function(event) {
       			// called when media returned from the MusicLibrary
                               console.log(event.items[0]);
                               console.log(event.items[0].title);
       		},
       		cancel : function() {
       			alert("Aborting ");
       		},
       		error : function(error) {
       			// called when there's an error
       			var a = Titanium.UI.createAlertDialog({
       				title : 'Music Library'
       			});
       			if (error.code == Titanium.Media.NO_MUSIC_PLAYER) {
       				a.setMessage('Please run this test on device.');
       			} else {
       				a.setMessage('Unexpected error: ' + error.code);
       			}
       			a.show();
       		}
       	});
       }
       
    It was just the log that didn't log all the properties of the media item, which is expected because it is an array of objects. So either iterate over the object keys or just check the [Ti.Media.openMusicLibrary|docs.appcelerator.com/platform/latest/#!/api/Titanium.Media-method-openMusicLibrary] docs.
  2. Abir Mukherjee 2017-01-20

    Tested with: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.1.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.1.0.v20170120115404 Appcelerator Studio, build: 4.8.1.201612050850 Xcode 8.2 iOS Device: 10 I tested this on an iOS 10 Device, and found that when I selected a song, the object type and the title are printed in the console. I tried this on 2 different songs and saw this in the console:
       [INFO] :   [object TiMediaItem]
       [INFO] :   Holocene
       [INFO] :   [object TiMediaItem]
       [INFO] :   The Miracle (Of Joey Ramone)
       
    The output shows that demo code works as expected.

JSON Source