Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

itunes sharing music

Discussion in 'iOS and tvOS' started by smokingbunny, Dec 27, 2014.

  1. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    hola everyone,

    trust everyone has had a pleasant chirstmas.
    got a question regarding itunes sharing and being able to embed music for users of my game.

    what i want to do is allow people to get the music from my game by using the itunes sharing thing, from where you see applications etc on your device.
    this is so people can have the soundtrack as a small 'thanks' for buying the game.

    would i have to create a duplicate of the tracks, or can it 'grab' the ones from within the game?
    but i just dont know where to go to find this. i currently dont have a full dev licence [yet] so cant test anything. has anyone else tried something like this?
    i know it can store save files and other things, but for music i dont know

    thanks
     
  2. Veemix

    Veemix

    Joined:
    Dec 5, 2014
    Posts:
    25
    Hey smokingbunny, are you just looking to access the iOS Music library? It's not clear what you mean by "itunes sharing thing". If it's the iOS Music library that you're after, you'll want to use iOS' MPMediaPickerController class.
     
  3. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    aye sorry for the lack of words ;)
    it was actually called 'file sharing' in iTunes [i was halfway with the words ;)], when viewing your iPad applications.

    but what it is is that i can have the album/music in a folder from within the iTunes 'file sharing' so people can just copy it off. i know about the music library, but thats not what I'm after just now. but have been thinking of putting it in

    thanks
     
  4. Veemix

    Veemix

    Joined:
    Dec 5, 2014
    Posts:
    25
    Ah, I know what you mean now. To enable file sharing for your app, you would have to add the UIFileSharingEnabled Key to your Info.plist file in your game's Xcode project. You will also need to set a CFBundleDisplayName in the plist file.

    Once that is set up, you'll need to make the music files accessible by copying them to the app's documents directory. You can get the path to this directory using Application.persistentDataPath. You'll probably need to copy the music files from their location within the Unity Assets directory to the document's directory. Have a look at this post to see how you can write bytes to the documents directory using System.IO.FileStream(). Hope this helps.