Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26829] iOS: Titanium.Media.openMusicLibrary returns empty items on iOS 9.3.5

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2019-04-25T12:00:09.000+0000
Affected Version/sRelease 7.5.0
Fix Version/sRelease 8.1.0
Componentsn/a
Labelsn/a
Reporteralessandro la rocca
AssigneeJan Vennemann
Created2019-02-07T10:29:44.000+0000
Updated2019-04-25T12:00:09.000+0000

Description

It works on iOS 10 or later, but fails on iOS 9.3.5 To reproduce: - select a song - music library will return an item - stringify will print an empty item - trying to read the title property on the item crashes the app
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,
		success : function(event) {
			// this will be printed
		        Ti.API.info(JSON.stringify(event));
			// this crashes the app even if items > 0
         		Ti.API.info('title = ' + 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();
		}
	});
}

Attachments

FileDateSize
log.txt2019-02-15T07:46:30.000+00008354
log.txt2019-02-07T11:13:29.000+0000101028
New Test 18-2-19 10-19 PM.crash2019-02-18T16:28:01.000+000044511

Comments

  1. Rakhi Mitro 2019-02-07

    Hello, Thanks for reporting this. Would you mind providing more information for the issues you are experiencing? It would be great if you can share the complete error logs using the following command: *appc run -p ios -T simulator -l trace*
  2. alessandro la rocca 2019-02-07

    This is the log directly from my app, not the sample I copied before. Anyway the specific code to get items by music gallery is the same. [^log.txt] When I try to read the "title" property of the first item selected, the app crashes.
  3. Fazlul Haque 2019-02-14

    Hello [~alarocca], I have tested this issue on my end and cannot reproduce the same crash on 7.5.0.GA. Please try the below code on your end and let us know. *Test Code:* app.js
       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();
       		}
       	});
       }
       
    tiapp.xml file
       </dict>
       	</plist>
              <key>NSAppleMusicUsageDescription</key>
       	<string>Play using while you are hiking</string>
       	</dict>
       </plist>
       
    Thanks
  4. alessandro la rocca 2019-02-15

    Thanks Fazlul, unfortunately even your code crashes on iOS 9.3.5 while it works on later iOS versions. Did you try it on a device running iOS 9.3.5? I just added a log on success to print the event. After this, the app crashes and does not print anything else. INFO] : Finished building the application in 10s 626ms [INFO] : Installing app on device: iPad [INFO] : App successfully installed on device: iPad Please manually launch the application -- Start application log ----------------------------------------------------- [INFO] : Test 1.0 (Powered by Titanium 7.5.0.2e5a7423d0) [INFO] : {"type":"success","representative":{},"types":1,"code":0,"success":true,"items":[{}],"source":{}} -- End application log -------------------------------------------------------
       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(JSON.stringify(event));
       			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();
       		}
       	});
       }
       
    [^log.txt]
  5. Fazlul Haque 2019-02-15

    Hi [~alarocca], Thanks for your feedback. Do you get this crash only iOS version iOS 9.3.5?. If you have any others device can you also check on that device and let us know? Actually, I have tested it upper iOS version
  6. alessandro la rocca 2019-02-15

    Yes, only iOS 9.3.5 does not work. Upper iOS versions works properly.
  7. Fazlul Haque 2019-02-15

    Thanks for the information. Yes, it's not working on iOS 9.3.5. I am going to assign it to our R&D team and they will take an action soon. Thanks
  8. Jan Vennemann 2019-02-27

    PR: https://github.com/appcelerator/titanium_mobile/pull/10729
  9. Samir Mohammed 2019-04-17

    FR Passed, waiting on Jenkins build.
  10. Samir Mohammed 2019-04-25

    *Closing ticket*, changes present in SDK Version 8.1.0.v20190423134840. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/10729

JSON Source