MPMoviePlayerController stills play after delete mp3 source file? - ios

I'm writing a app to play media file.I use MPMoviePlayerController.
My source:
NSURL * mp3URL = [NSURL fileURLWithPath:mp3Path];
MPMoviePlayerController *mpv = [[MPMoviePlayerController alloc] init];
[mpv setContentURL:mp3URL];
But when i delete mp3Path,mpv stills play.
In this case,MPMoviePlayer creates a tmp file,load data from mp3Path to tmp path and play this tmp file?
Can anyone explain to me?Thanks so much.

yes it creates a tmp file, thats why you have the notifications for didloadfinish and didpreloadfinish if the file did load completely it is gonna play the whole song...

Related

Playing several tracks saved locally in sequence

I need to play n tracks one after another with ability to switch to next/previous song and pause. Songs are located in Documents folder.
I looked in AVQueuePlayer, but it seems that this approach is not working with local files, playing by url works fine. Now i can play one song with AVAudioPlayer like this:
NSURL *url = [NSURL fileURLWithPath:[node path]];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[self.player play];
But it seems that playing bunch of tracks one after another this way is not the best practice.
May be there are frameworks that implement this in more convenient way?
Any suggestions?
StreamingKit is probably what your looking for.

GPUImage and AVAssetWriter writes files to where?

I am trying to use Brad Larson's GPUImage library to record a video file. So far, the issue I am running into is the following piece of code:
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
This is picked up directly from his example from his GitHub page
https://github.com/BradLarson/GPUImage
Now, I looked at the source code and I see he does the usual AVFoundation stuff - creates AVAssetWriter instance and adds inputs to it. MY question here is that where is #"Documents/Movie.m4v" located? How can I play this video back? Or how do I even access it? I know it is located in an arbitrary location where the app bundle is copied during run-time. My goal is to be able to write the video into the Gallery or atleast an album in Gallery that is created by my app. Does anyone know where the file is being written to?
Maybe I'm misunderstanding, but the movie is at the path pathToMovie (or URL movieURL.
You can play it back with something like this:
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
// later
AVPlayerViewController *avc = [[AVPlayerViewController alloc] init];
avc.player = [[AVPlayer alloc] initWithURL:movieURL];
[myViewController presentViewController:avc animated:YES completion:nil];
If you want to download the file to your computer, you can select your connect device in Xcode > Devices, then select your app and download the package. Your movie will be in the Documents directory.
To save it to the gallery, do
// TODO: use completion arguments for a better user experience
UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie,nil,nil,nil);

Playing audio files continually using audio recorded url

I am newcomer in Objective-C and have experience only 12 months in iPhone development.
I am recording audio files in One UIViewController, and playing on another UIViewController. For playing purpose i am saving the date string for generation of url,it is fine working properly,
But ,now my problem is i want to play previous audio record file for some time after that i want to play next audio file using url . i am saving all the data using nsuser dafaults please help me
NSM![enter image description here][1]utableArray *dateString;
NSURL recordFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:[self.dateString objectAtIndex:sender.tag]]];
For playing
player = [[AVAudioPlayer alloc] initWithContentsOfURL:recordFile error:&error];
from fig when i click a tag 2 i want to play first 5 sec tag1 after that i want to play tag2
Record the audio -> Save the audio in the Temp -> Track the saved path of the audio file (You can store this saved path in an array) . Repeat the same steps for the next file.
Use AVQueuePlayerfor playing items one after the other.

How to play an array of songs using streamingkit library

Has anyone out there ever used this https://github.com/tumtumtum/StreamingKit/ package to play remote mp3 files? How can one load an array of music urls and play them one after the other?
Just as document says:
STKAudioPlayer* audioPlayer = [[STKAudioPlayer alloc] init];
[audioPlayer queue:#"http://www.abstractpath.com/files/audiosamples/sample.mp3"];
[audioPlayer queue:#"http://www.abstractpath.com/files/audiosamples/airplane.aac"];
You just need to add url to queue.

AVAudioPlayer not working with .pls shoutcast file?

Good Day,
I am working on one Radio APP that gets shoutcast streaming .pls file and plays it with help of AVFoundation framework.
This job is easily done with AVPlayer, but the problem with it is that I can not code or find any good solution to get it working with volume slider, the AVPlayer class does not have volume property.
So now I am trying to get it working with AVAudioPlayer which has volume property, and here is my code:
NSString *resourcePatch = #"http://vibesradio.org:8002/listen.pls";
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePatch]];
NSError *error;
vPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
vPlayer.numberOfLoops = 0;
vPlayer.volume = 1.0f;
if (vPlayer == nil)
NSLog(#"%#", [error description]);
else
[vPlayer play];
This code is working with uploaded .mp3 files on my server but it is not working with .pls files generated by shoutcast,
Is there any way to fix AVAudioPlayer to work with .pls files, or implement volume slider to AVPlayer ?
Using AVAudioPlayer for stream from network is not a good idea. See what Apple's documentation say on AVAudioPlayer:
An instance of the AVAudioPlayer class, called an audio player,
provides playback of audio data from a file or memory.
Apple recommends that you use this class for audio playback unless you
are playing audio captured from a network stream or require very low
I/O latency.
For change AVPlayer's volume check this question:Adjusting the volume of a playing AVPlayer

Resources