iOS Can I play AAC file between 8m24s to 12m03s?

mikezang

macrumors 6502a
Original poster
May 22, 2010
772
1
Tokyo, Japan
I have a AAC file, I want to play it in my app, and I hope that I can play it from any time in any interval, is it easy and possible?
 

weichsel

macrumors newbie
May 23, 2013
12
3
You could use AVFoundation to play your AAC file on iOS.
A good starting point is the AVPlayerDemo sample code from Apple:
http://developer.apple.com/library/ios/#samplecode/AVPlayerDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010101

The above sample shows how to play back a video using AVPlayer. (AVFoundation also can be used to play audio-only files)

To accomplish your specific task (playing only a certain interval of a file), you can use AVPlayer's seekToTime method in combination with a time boundary observer:
http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/occ/instm/AVPlayer/addBoundaryTimeObserverForTimes:queue:usingBlock:
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
772
1
Tokyo, Japan
You could use AVFoundation to play your AAC file on iOS.
A good starting point is the AVPlayerDemo sample code from Apple:
http://developer.apple.com/library/ios/#samplecode/AVPlayerDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010101

The above sample shows how to play back a video using AVPlayer. (AVFoundation also can be used to play audio-only files)

To accomplish your specific task (playing only a certain interval of a file), you can use AVPlayer's seekToTime method in combination with a time boundary observer:
http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/occ/instm/AVPlayer/addBoundaryTimeObserverForTimes:queue:usingBlock:
That sample is to show how playing file in Library, I want to play audio file in bundle? is there any sample?
 

weichsel

macrumors newbie
May 23, 2013
12
3
Just pass an URL to your media file to AVPlayer (using the AVPlayer initWithURL initializer).
You can obtain an URL to a resource within your main bundle via NSBundle.
e.g.:
Code:
NSURL* audioFileURL = [[NSBundle mainBundle] URLForResource:@"mediaFilename" withExtension:@"m4a"];
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
772
1
Tokyo, Japan
Just pass an URL to your media file to AVPlayer (using the AVPlayer initWithURL initializer).
You can obtain an URL to a resource within your main bundle via NSBundle.
e.g.:
Code:
NSURL* audioFileURL = [[NSBundle mainBundle] URLForResource:@"mediaFilename" withExtension:@"m4a"];
I have a lot of pictures and they divide d to groups, one group has a relevant AAC file, when a picture is showed, play specific segment in relevant AAC file, is this easy to implement?
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
447
The Centennial State
I have a lot of pictures and they divide d to groups, one group has a relevant AAC file, when a picture is showed, play specific segment in relevant AAC file, is this easy to implement?
Perhaps you missed this part:

To accomplish your specific task (playing only a certain interval of a file), you can use AVPlayer's seekToTime method in combination with a time boundary observer:
http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/occ/instm/AVPlayer/addBoundaryTimeObserverForTimes:queue:usingBlock:
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Yeah, I read it.
In fact, I want to read .srt file and show it on images and play sound background base on contents of file .srt, do you have any more detail suggestion?
"...read .srt file and show it on images..."

"play sound background base on contents of file .srt?"

"any more detail suggestions?"

That's some serious word salad you've got going there.


Here's a suggestion. Learn to describe your problem well enough so others can understand it.

Then do you own research, experiment with the things you find, and post CONCRETE, SPECIFIC QUESTIONS on the specific things you have having problems with.

Don't post ill-formed questions look for others to do all your work for you.

When you can't be bothered to even describe what you are doing clearly then why should others invest the time to play 20 questions with you to figure out what you are talking about, research the answer, and provide it to you?

Edit: This guy puts it really well: What have you tried
 
Last edited: