iTunes.Play issue, crash when playing an url

Hi,

I’m trying to use the iTunes plugin to allow a user to play selected mp3.

It seems it’s not possible to play an mp3 when you already know its url.

How I did:

  • I used the iTunes sample to select and play an mp3 from my device. I log the song url.

  • I modified the sample to play the song without picking it with iTunes.show :

[lua] iTunes.play( “ipod-library://item/item.mp3?id=5118609324351194125”, onPlaybackEnded )

[/lua]

This code crash the app.

The problem with doing this is that what if the user deletes a song from their iTunes library between sessions and you are logging that song and trying to play it?

I admit it shouldn’t crash though, but I think it’s good practise to always show the picker between sessions.

Euphoriacorina, you’re right. But in my app, the user selects some tracks for a future use.

If the iTunes.play API should return an error message (or just true or false), it will help to detect that the song was deleted.

It’s definitely a bug :frowning:

Could you post up the sample code you used?
I can test it on my end to confirm it for you.

Thanks euphoriacorona!

Basically, you just have to download the sample from Corona here:

https://github.com/coronalabs/plugins-sample-iTunes

Then, uncomment the line in onMediaChosen:

print( “url={”… event.data[i].url…"}")

Launch the app on a device, and copy paste the song url from the console.

Then, modify the code to play the song like this, without opening the picker first:

[lua] iTunes.play( “ipod-library://item/item.mp3?id=6252655240146942054”, onPlaybackEnded )
[/lua]

for example by replacing iTunes.show by this iTunes.play code…

Run the app again, and test.

After looking at some Objective C code, regarding the media picker, my opinion is that the init of the media picker is only in the iTunes.show method from the plugin, when it should be separated, allowing to play a song without opening the picker first.

Here is the crash report.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)

Exception Subtype: KERN_INVALID_ADDRESS at 0x00000010

Triggered by Thread:  0

Thread 0 Crashed:

0   plugins-sample-iTunes-master      0x001351bc ___lldb_unnamed_function1987$$plugins-sample-iTunes-master + 132

1   plugins-sample-iTunes-master      0x00136d12 ___lldb_unnamed_function2044$$plugins-sample-iTunes-master + 42

2   plugins-sample-iTunes-master      0x001d6b7c Corona::iTunesLibrary::play(lua_State*) (iTunesLibrary.mm:185)

3   plugins-sample-iTunes-master      0x0013bf1e ___lldb_unnamed_function2171$$plugins-sample-iTunes-master + 986

4   plugins-sample-iTunes-master      0x00148926 ___lldb_unnamed_function2420$$plugins-sample-iTunes-master + 1474

5   plugins-sample-iTunes-master      0x0013c0f2 ___lldb_unnamed_function2173$$plugins-sample-iTunes-master + 74

6   plugins-sample-iTunes-master      0x00135b34 ___lldb_unnamed_function1999$$plugins-sample-iTunes-master + 12

7   plugins-sample-iTunes-master      0x00149694 ___lldb_unnamed_function2427$$plugins-sample-iTunes-master + 88

8   plugins-sample-iTunes-master      0x0013c322 ___lldb_unnamed_function2177$$plugins-sample-iTunes-master + 58

9   plugins-sample-iTunes-master      0x00135b08 ___lldb_unnamed_function1998$$plugins-sample-iTunes-master + 228

10  plugins-sample-iTunes-master      0x001594f2 ___lldb_unnamed_function3449$$plugins-sample-iTunes-master + 58

11  plugins-sample-iTunes-master      0x00186f94 ___lldb_unnamed_function5213$$plugins-sample-iTunes-master + 108

12  plugins-sample-iTunes-master      0x00186faa ___lldb_unnamed_function5214$$plugins-sample-iTunes-master + 10

13  plugins-sample-iTunes-master      0x00155242 ___lldb_unnamed_function3047$$plugins-sample-iTunes-master + 306

14  plugins-sample-iTunes-master      0x001553d0 ___lldb_unnamed_function3049$$plugins-sample-iTunes-master + 180

15  plugins-sample-iTunes-master      0x00155790 ___lldb_unnamed_function3060$$plugins-sample-iTunes-master + 156

16  plugins-sample-iTunes-master      0x0016c10e ___lldb_unnamed_function4260$$plugins-sample-iTunes-master + 38

17  plugins-sample-iTunes-master      0x000e873a ___lldb_unnamed_function499$$plugins-sample-iTunes-master + 310

18  UIKit                             0x303dadd4 -[UIWindow _sendTouchesForEvent:] + 524

19  UIKit                             0x303d5e60 -[UIWindow sendEvent:] + 828

20  UIKit                             0x303ab798 -[UIApplication sendEvent:] + 192

21  UIKit                             0x303a9f9e _UIApplicationHandleEventQueue + 7094

22  CoreFoundation                    0x2dbff180 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12

23  CoreFoundation                    0x2dbfe64e __CFRunLoopDoSources0 + 202

24  CoreFoundation                    0x2dbfce42 __CFRunLoopRun + 618

25  CoreFoundation                    0x2db67c22 CFRunLoopRunSpecific + 518

26  CoreFoundation                    0x2db67a06 CFRunLoopRunInMode + 102

27  GraphicsServices                  0x3288e27e GSEventRunModal + 134

28  UIKit                             0x3040b044 UIApplicationMain + 1132

29  plugins-sample-iTunes-master      0x000d7d7a ___lldb_unnamed_function1$$plugins-sample-iTunes-master + 62

30  plugins-sample-iTunes-master      0x000d7d34 start + 36

Hey man.

I haven’t had time to try this yet. I would suggest writing up a test case and submitting it to Corona via the report a bug link at the top of the page. That way they can look into it.

The problem with doing this is that what if the user deletes a song from their iTunes library between sessions and you are logging that song and trying to play it?

I admit it shouldn’t crash though, but I think it’s good practise to always show the picker between sessions.

Euphoriacorina, you’re right. But in my app, the user selects some tracks for a future use.

If the iTunes.play API should return an error message (or just true or false), it will help to detect that the song was deleted.

It’s definitely a bug :frowning:

Could you post up the sample code you used?
I can test it on my end to confirm it for you.

Thanks euphoriacorona!

Basically, you just have to download the sample from Corona here:

https://github.com/coronalabs/plugins-sample-iTunes

Then, uncomment the line in onMediaChosen:

print( “url={”… event.data[i].url…"}")

Launch the app on a device, and copy paste the song url from the console.

Then, modify the code to play the song like this, without opening the picker first:

[lua] iTunes.play( “ipod-library://item/item.mp3?id=6252655240146942054”, onPlaybackEnded )
[/lua]

for example by replacing iTunes.show by this iTunes.play code…

Run the app again, and test.

After looking at some Objective C code, regarding the media picker, my opinion is that the init of the media picker is only in the iTunes.show method from the plugin, when it should be separated, allowing to play a song without opening the picker first.

Here is the crash report.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)

Exception Subtype: KERN_INVALID_ADDRESS at 0x00000010

Triggered by Thread:  0

Thread 0 Crashed:

0   plugins-sample-iTunes-master      0x001351bc ___lldb_unnamed_function1987$$plugins-sample-iTunes-master + 132

1   plugins-sample-iTunes-master      0x00136d12 ___lldb_unnamed_function2044$$plugins-sample-iTunes-master + 42

2   plugins-sample-iTunes-master      0x001d6b7c Corona::iTunesLibrary::play(lua_State*) (iTunesLibrary.mm:185)

3   plugins-sample-iTunes-master      0x0013bf1e ___lldb_unnamed_function2171$$plugins-sample-iTunes-master + 986

4   plugins-sample-iTunes-master      0x00148926 ___lldb_unnamed_function2420$$plugins-sample-iTunes-master + 1474

5   plugins-sample-iTunes-master      0x0013c0f2 ___lldb_unnamed_function2173$$plugins-sample-iTunes-master + 74

6   plugins-sample-iTunes-master      0x00135b34 ___lldb_unnamed_function1999$$plugins-sample-iTunes-master + 12

7   plugins-sample-iTunes-master      0x00149694 ___lldb_unnamed_function2427$$plugins-sample-iTunes-master + 88

8   plugins-sample-iTunes-master      0x0013c322 ___lldb_unnamed_function2177$$plugins-sample-iTunes-master + 58

9   plugins-sample-iTunes-master      0x00135b08 ___lldb_unnamed_function1998$$plugins-sample-iTunes-master + 228

10  plugins-sample-iTunes-master      0x001594f2 ___lldb_unnamed_function3449$$plugins-sample-iTunes-master + 58

11  plugins-sample-iTunes-master      0x00186f94 ___lldb_unnamed_function5213$$plugins-sample-iTunes-master + 108

12  plugins-sample-iTunes-master      0x00186faa ___lldb_unnamed_function5214$$plugins-sample-iTunes-master + 10

13  plugins-sample-iTunes-master      0x00155242 ___lldb_unnamed_function3047$$plugins-sample-iTunes-master + 306

14  plugins-sample-iTunes-master      0x001553d0 ___lldb_unnamed_function3049$$plugins-sample-iTunes-master + 180

15  plugins-sample-iTunes-master      0x00155790 ___lldb_unnamed_function3060$$plugins-sample-iTunes-master + 156

16  plugins-sample-iTunes-master      0x0016c10e ___lldb_unnamed_function4260$$plugins-sample-iTunes-master + 38

17  plugins-sample-iTunes-master      0x000e873a ___lldb_unnamed_function499$$plugins-sample-iTunes-master + 310

18  UIKit                             0x303dadd4 -[UIWindow _sendTouchesForEvent:] + 524

19  UIKit                             0x303d5e60 -[UIWindow sendEvent:] + 828

20  UIKit                             0x303ab798 -[UIApplication sendEvent:] + 192

21  UIKit                             0x303a9f9e _UIApplicationHandleEventQueue + 7094

22  CoreFoundation                    0x2dbff180 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12

23  CoreFoundation                    0x2dbfe64e __CFRunLoopDoSources0 + 202

24  CoreFoundation                    0x2dbfce42 __CFRunLoopRun + 618

25  CoreFoundation                    0x2db67c22 CFRunLoopRunSpecific + 518

26  CoreFoundation                    0x2db67a06 CFRunLoopRunInMode + 102

27  GraphicsServices                  0x3288e27e GSEventRunModal + 134

28  UIKit                             0x3040b044 UIApplicationMain + 1132

29  plugins-sample-iTunes-master      0x000d7d7a ___lldb_unnamed_function1$$plugins-sample-iTunes-master + 62

30  plugins-sample-iTunes-master      0x000d7d34 start + 36

Hey man.

I haven’t had time to try this yet. I would suggest writing up a test case and submitting it to Corona via the report a bug link at the top of the page. That way they can look into it.

This bug has been fixed in the latest version of the plugin. Please try the latest daily build and let us know if you have any further issues. Thanks!

This bug has been fixed in the latest version of the plugin. Please try the latest daily build and let us know if you have any further issues. Thanks!