mpmovieviewcontroller not working in iPad application? - ios5

Below is my code for setting up mpmoviecontroller. Although I can hear the sound of the video, I cannot see the pictures of the video. I've searched through internet, but I could not find an error for my code. Could someone help me get out of this dilemma?
(Note that the path and url are correct~ :))
- (IBAction)playClicked:(id)sender {
NSString *path=[[NSBundle mainBundle] bundlePath];
path=[path stringByAppendingPathComponent:#"movies.bundle"];
path=[path stringByAppendingPathComponent:#"mean.mp4"];
NSURL *url=[NSURL fileURLWithPath:path];
NSFileManager *filemanager=[NSFileManager defaultManager];
if([filemanager fileExistsAtPath:path]){
NSLog(#"File exists at %#! You should be able to see the movie!:)",path);
MPMoviePlayerController *player=[[MPMoviePlayerController alloc] initWithContentURL:url];
if(player){
player.scalingMode = MPMovieScalingModeNone;
player.controlStyle=MPMovieControlStyleFullscreen;
player.movieSourceType=MPMovieSourceTypeFile;
[player.view setFrame:CGRectMake(0, navigationBar.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height-navigationBar.bounds.size.height)];
[self.view addSubview:player.view];
[player prepareToPlay];
NSLog(#"Ready to play for %#!",player.duration);
[player play];
NSLog(#"Played!");
}
}else{
NSLog(#"File does not exist!:(");
}
}
RUNTIME ERRORS:
2012-02-06 08:54:40.248 Board[1604:11f03] File exists at /Users/admin/Library/Application Support/iPhone Simulator/5.0/Applications/C468351E-3150-4397-B73A-8505D099B2C5/Board.app/movies.bundle/mean.mp4! You should be able to see the movie!:)
2012-02-06 08:54:40.276 Board[1604:11f03] Ready to play for (null)!
2012-02-06 08:54:40.277 Board[1604:11f03] Played!
[Switching to process 1604 thread 0x13e03]
[Switching to process 1604 thread 0x11f03]
2012-02-06 08:54:40.733 Board[1604:11f03] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.740 Board[1604:11f03] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.886 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.894 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.905 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.928 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.940 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-02-06 08:54:40.947 Board[1604:11f03] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security

It seems that adding the code below will do the work.
player.movieSourceType=MPMovieSourceTypeFile;
[self.view addSubview:player.view];
[player setFullscreen:YES];

Related

NSCocoaErrorDomain Code=256 File couldn’t be opened

The file were created in old project in Objective-C.
NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:dataForWrite];
[archiver encodeObject:dictVer forKey:#"cityVersionDict"];
[archiver finishEncoding];
BOOL flag = [dataForWrite writeToFile:path atomically:YES];
I want to read this file in new project in Swift4.0 by the code like this:
do {
let data = try Data.init(contentsOf: path)
} catch {
print(error)
}
then catch error:
Error Domain=NSCocoaErrorDomain Code=256 "The file “cityVersionDict.archiver” couldn’t be opened." UserInfo={NSURL=/Users/sam/Library/Developer/CoreSimulator/Devices/51CD0088-EE62-4ED0-8660-4C6486BC7823/data/Containers/Data/Application/5740ADE1-4930-4968-B86F-7E2F5F99F5F8/Library/Caches/cityVersionDict.archiver}
In Objective-C ,this file can be read normally .I already double check the path is right. but still catch error. please help, thanks
I find the problem is about the URL.
The URL must use init(fileURLWithPath: String) to created,
then Data(contentsOf: URL) can work fine.

Accessing an sqlite3 file with Core Data

I'm doing the second part of Ray Wenderlich's Core Data Tutorial. Instead of reading the file that contains the default data, I'm trying to read the actual Failed Bank datafile that was created in his SQLite3 tutorial. The program is throwing an exception when I try to create the Store and open the File.
Here is the code snippet
- (NSPersistentStoreCoordinator *) persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"banklist.sqlite3"];
if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {
NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"banklist" ofType:#"sqlite3"]];
NSError *err = nil;
if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err]) {
NSLog(#"Opps, couldn't copy preloaded data");
}
}
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
Here is the exception:
2013-09-16 20:19:57.549 FailedBankCD[4086:c07] CoreData: error: (1) I/O error for database at /Users/artletter1/Library/Application Support/iPhone Simulator/6.1/Applications/524B84E3-94D6-40A3-8847-DD15A99B22A2/Documents/banklist.sqlite3. SQLite error code:1, 'no such table: Z_METADATA'
2013-09-16 20:19:57.552 FailedBankCD[4086:c07] Unresolved error Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x854b560 {NSUnderlyingException=I/O error for database at /Users/artletter1/Library/Application Support/iPhone Simulator/6.1/Applications/524B84E3-94D6-40A3-8847-DD15A99B22A2/Documents/banklist.sqlite3. SQLite error code:1, 'no such table: Z_METADATA', NSSQLiteErrorDomain=1}, {
NSSQLiteErrorDomain = 1;
NSUnderlyingException = "I/O error for database at /Users/artletter1/Library/Application Support/iPhone Simulator/6.1/Applications/524B84E3-94D6-40A3-8847-DD15A99B22A2/Documents/banklist.sqlite3. SQLite error code:1, 'no such table: Z_METADATA'";
}
Thanks!
Roy
To accomplish what you intend to do you will have to go through the tables of your sqlite file using the sqlite3 API, insert new Core Data entities, fill them with the data and save to a different file.
.

ios not finding a txt file using stringWithContentsOfFile

I have a text file thetext.txt. Which is in my project and is copied on build, in build settings. In the same way that my GL shaders and textures are (which work fine.)
NSError *errorReading;
NSArray *linesOfText = [[NSString stringWithContentsOfFile:#"thetext.txt"
encoding:NSUTF8StringEncoding
error:&errorReading]
componentsSeparatedByString:#"\n"];
NSLog(#"Reading error %#",errorReading);
It prints the following to console.
Reading error Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x896fff0 {NSFilePath=thetext.txt, NSUnderlyingError=0x896ff60 "The operation couldn’t be completed. No such file or directory"}
Have I missing something?
This fails because you are passing the file name and not the path to the file. Try something like this
NSString* filePath = [[NSBundle mainBundle] pathForResource:#"thetext" ofType:#"txt"];
NSError *errorReading;
NSArray *linesOfText = [[NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:&errorReading]
componentsSeparatedByString:#"\n"];
NSLog(#"Reading error %#",errorReading);
Hopefully there will be no error!

Can't Play Sound on Xcode iphone simulator

I am trying to play a sound thats linked to a button, but I get the following error code. How can I fixed this problem?
2012-01-13 07:22:58.887 M3NYFAC3Z[5875:1e03] Error loading
/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:
dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,
262): Symbol not found: _CFXMLNodeGetInfoPtr Referenced from:
/System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-01-13 07:22:58.892 M3NYFAC3Z[5875:1e03] Error loading
/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:
dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,
262): Symbol not found: _CFXMLNodeGetInfoPtr Referenced from:
/System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-01-13 07:25:28.994 M3NYFAC3Z[5875:1e03] AQMEIO_Base::DoStartIO:
timeout 2012-01-13 07:25:29.271 M3NYFAC3Z[5875:1e03]
AQMEDevice(0x8831a00)::StartIO: error -66681 2012-01-13 07:25:29.272
M3NYFAC3Z[5875:1e03] CA_UISoundClientBase::StartPlaying:
AddRunningClient failed (status = -66681). [Switching to process 5875
thread 0x207] sharedlibrary apply-load-rules all
This is my code:
-(IBAction)playobey:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"renegadeyamaha" ofType:#"wav"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
}
You need to keep a reference to your AVAudioPlayer in an ivar/property somewhere. It's probably being created and then released immediately before it's had a chance to finish playing your sound.
I wrote a little AVAudioPlayer-based sound player class that might make your life easier:
https://github.com/nicklockwood/SoundManager

Using exportAsynchronouslyWithCompletionHandler

I try to export an audio file from the iPod-Library. I want to create with this iPod-Library file an new file. In the AV Foundation Programming Guide in chapter Reading and Writing Assets there is a little example. However this code doesn't work for me. 4 errors happens
Export Status 4 Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed"
UserInfo=0x1edfa0 {NSLocalizedFailureReason=An unknown error occurred (-12124),
NSUnderlyingError=0x1ebdc0 "The operation couldn’t be completed. (OSStatus error -12124.)",
NSLocalizedDescription=The operation could not be completed}
My code
AVURLAsset *objAvUrlAsset = [[AVURLAsset alloc] initWithURL:[tempArray objectAtIndex:0] options:nil];
NSLog(#"%s objAvUrlAsset %#", __FUNCTION__, objAvUrlAsset);
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:objAvUrlAsset];
NSLog(#"%s compatiblePresets %#", __FUNCTION__, compatiblePresets);
if ([compatiblePresets containsObject:AVAssetExportPresetAppleM4A]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:objAvUrlAsset presetName:AVAssetExportPresetAppleM4A];
NSString * exportPath = [NSString stringWithFormat:#"testTrack1.M4A"];
NSURL *exportURL = [NSURL fileURLWithPath:exportPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.shouldOptimizeForNetworkUse = YES;
NSLog(#"%s export Session %#",__FUNCTION__, exportSession);
[exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
// export completed
NSLog(#"Export Status %d %#", exportSession.status, exportSession.error);
}];
[exportSession release];
}
the nslog message
-[MyLocalMusicLibrary getAllTracks] objAvUrlAsset AVURLAsset: 0x1dd5a0, URL = ipod-library://item/item.mp3?id=-212958261728896866
-[MyLocalMusicLibrary getAllTracks] compatiblePresets (
AVAssetExportPresetAppleM4A,
AVAssetExportPreset960x540,
AVAssetExportPresetLowQuality,
AVAssetExportPresetMediumQuality,
AVAssetExportPreset640x480,
AVAssetExportPresetHighestQuality,
AVAssetExportPreset1280x720
)
-[MyLocalMusicLibrary getAllTracks] export Session AVAssetExportSession: 0x1e85c0,
asset = AVURLAsset: 0x1dd5a0, URL = ipod-library://item/item.mp3?id=-212958261728896866,
presetName = AVAssetExportPresetAppleM4A, outputFileType = com.apple.m4a-audio
-[MyLocalMusicLibrary getAllTracks] Export Status 4 Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed"
UserInfo=0x1edfa0 {NSLocalizedFailureReason=An unknown error occurred (-12124),
NSUnderlyingError=0x1ebdc0 "The operation couldn’t be completed. (OSStatus error -12124.)",
NSLocalizedDescription=The operation could not be completed}
How can i fix this four errors. Do i need for this export the AVAssetReader and AVAssetWriter.
I got the same result from AVAssetExportSession, what the completely useless NSError is trying to tell you is that the path you're exporting to doesn't fully exist. You'll want to make sure that you create the path to the directory you're placing the file in using NSFileManager.
The problem for me was that I was trying to convert the file directly from the tmp directory after getting it from the UIImagePickerController
What I had to do was first save the file to the Library, then iterate over the ALAssetLibrary files to find the latest video saved. Then I converted that video to .mp4 and stored it int he application's local documents directory for use as I please.
Kind of ridiculous that this is necessary but it works.