2

I am trying to loop a segment of an MP3 loaded from the users iPod library. By segment I mean, I don't want to loop the entire MP3 but only a section of it.

So say the MP3 is 4 minutes long, I have defined startTime, and endTime.

When the play button is hit, I seek the player to startTime and begin play.

I'm also subscribed to the event listener [AVPlayer addBoundaryTimeObserverForTimes:...] to be notified when my endTime has hit. At which point, I seek back to startTime and play.

** However, this does not provide a seamless loop - there is a split second where the sound stops before playing at startTime again.. My application is music making software, so it is important that the loop is perfect. Please help!

Andy Hin
  • 30,345
  • 42
  • 99
  • 142
  • 1
    At a glance I can suggest: you may cut the exact part from the audio file and simply loop the whole file. – 0xDE4E15B Aug 29 '12 at 20:11
  • Thanks for the suggestion. I was considering this, although I don't know if Apple's policy allows for saving MP3 files from their iPod library. Will definitely explore this more though. – Andy Hin Aug 29 '12 at 20:30
  • 1
    @AndyHin it does. There's te AVAssetWriter class which does exactly that. –  Sep 06 '12 at 19:58
  • To understand how MP3 works, I would read this link. Helps you understand why you get the silent parts: http://www.compuphase.com/mp3/mp3loops.htm – audub Sep 07 '12 at 11:50

1 Answers1

1

Apple has a Technical Q&A called Exporting a Trimmed Audio Asset.

Also, take a look at this thread, which deals with trimming an AVAsset audio file.

Community
  • 1
  • 1
Michael Frederick
  • 16,664
  • 3
  • 43
  • 58