How can we get the video which are stored in the iphone library and Can we save that in our local database in our app and then we will delete the video from the iPhone Library, so that the video cannot be able to access in the iPhone library, but it can be used in the app.
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * fetchPath = [documentsDirectory stringByAppendingPathComponent:#"TestDemo"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:fetchPath] == YES) {
[fileManager removeItemAtPath:fetchPath error:nil];
}
NSError * error = nil;
if (Videourl == nil) {
return;
}
[appDelegateIphone showLoadingViewforLandScapeRight];
[[NSFileManager defaultManager] copyItemAtURL:url
toURL:[NSURL fileURLWithPath:fetchPath]
error:&error];
You can use UIImagePickerController for retrieving images and videos from the iPhone Library.
You are not able to delete any image or videos from the iPhone library.
Use the UIImagePickerController class, and set the sourceType to be UIImagePickerControllerSourceTypePhotoLibrary (this will present the user with the dialogue to choose an item from their iPhone library).
The delegate method didFinishPickingMediaWithInfo will then return a URL to the video the user has selected.
You cannot delete a video stored in the iPhone library. However, you could use the UIImagePickerController to prompt the user to record a video. You can then save this video to the file area of your app. By default it will not be saved to the iPhone library.
Check out the Apple documentation for more info.
Hope that helps.
Related
I am using a UIWebView control and opening a web page URL on it in landscape mode only. In this URL on a particular event a PDF is getting opened. This time the PDF is not getting opened properly (it always shows only first page of the PDF file), and in the Output window i am getting "flatedecode decoding error".
Is there any way so that my application can catch that PDF opening event, and I can open the PDf in Safari or some other browser rather than UIWebView?
Or is there any way in Phonegap to achieve this?
I guess you only need a way to find out whether the specific link opening the PDF is clicked or not?
Make sure you make your viewcontroller a delegate for the webview. Then implement this method
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
navigationType will be UIWebViewNavigationTypeLinkClicked when a new page loads on link click.
request will tell you the URL being opened and you can listen if the URL is one of your PDF. If it is then you can handle it in the method however you want to - download it and open in another web view or open in safari.
More details here.
You can save PDF in your document directory by using this code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
//You must check if this directory exist every time
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO)
{
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}
NSString *filePath = [cachePath stringByAppendingPathComponent:#"QRScanner.pdf"];
//webView.request.URL contains current URL of UIWebView, don't forget to set outlet for it
NSData *pdfFile = [NSData dataWithContentsOfURL:webView.request.URL];
if(pdfFile)
{
[AppDelegate obj_appDelegate].Alertview.hidden = YES;
[[AppDelegate obj_appDelegate].activity stopAnimating];
}
[pdfFile writeToFile:filePath atomically:YES];
I have made an iphone application in which i am getting songs from itunes library and display in table as well as store them in my document directory. Now i want to make it secret..So i want to delete the selected file from itunes library so it wont be displayed in list. Can anyone help me to do this??
Code:
importableDoc = [NSMutableArray array];
// Get public docs dir
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *publicDocumentsDir = [paths objectAtIndex:0];
// Get contents of documents directory
NSError *error;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:publicDocumentsDir error:&error];
if (files == nil) {
NSLog(#"Error reading contents of documents directory: %#", [error localizedDescription]);
}
// Add all mp3 files to a list
for (NSString *file in files) {
if ([file.pathExtension compare:#"mp3" options:NSCaseInsensitiveSearch] == NSOrderedSame)
{
NSString *fullPath = [publicDocumentsDir stringByAppendingPathComponent:file];
//NSLog(#"fullPath : %#",fullPath);
[importableDoc addObject:fullPath];
}
}
}
Sorry, but it looks like you're out of luck. From Media Player Framework Reference:
The Media Player framework provides facilities for playing movie,
music, audio podcast, and audio book files. This framework also gives
your application access to the iPod library, letting you find and play
audio-based media items synced from iTunes on the desktop. iPod
library access is read-only.
As an alternative, instead of using a MPMediaPickerController you could use MPMediaQueries to display your own custom list of songs available, but that still doesn't give you to opportunity to actually remove tracks from the users iPod library.
In my app I imported 4 sound files. Now I want to list all the sound files in a View. When the user clicks any one of the sound, it needs to be selected and played as like in the Alarms app (choosing the sound for alarm). The difference here is I am getting the sound from my project. I have searched in SO and Google but I couldn't find a solution exactly for this problem.
Assuming that "In my app i imported 4 sound files" means that the files are in your app bundle (and also assuming that the extension of the files is MP3 - you can change it to whatever extensions they actually have):
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *mgr = [[NSFileManager alloc] init];
NSArray *allFiles = [mgr contentsOfDirectoryAtPath:bundlePat error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:#"mp3"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
// fullFilePath now contains the path to your MP3 file
DoSomethingWithFile(fullFilePath);
}
}
I stored videos in my document directory from photo library. Now i want to show all videos which are stored in my document directory.. but i don't know how its possible???
Actually i want to display all videos as like its open in photo library(four videos in a single row).. and when i click on any video... the video is start playing...
can anybody help me which is the best way to show all videos from document directory to ViewController....
Thanx......
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
NSData * movieData = [NSData dataWithContentsOfURL:movieURL];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self imageNameTextField]text]];
fullPath = [fullPath stringByAppendingFormat:#".MOV"];
[ movieData writeToFile:fullPath atomically:YES];
}
I recommend you to use an open-source grid-view control. You can find them in GitHub. For instance, BDDynamicGridViewController is interesting. But it is not the only option. There is also AQGridView.
Also, there is a popular open-source library, called Three20 and it has it's upgrade, called Nimbus. This library has a custom control for displaying photos grid. You can use the same for displaying video thumbnails grid. For instance, try this.
After you will manage to use or create Grid view control, you will need thumbnail generator for the videos. Use this topic for that purpose.
To get access to the videos stored in the photo library on the device you need to use the Asset library. The following code shows you how to get access to the first video in the photo library :
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just videos.
[group setAssetsFilter:[ALAssetsFilter allVideos]];
// For this example, we're only interested in the first item.
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
// Now you have the AV asset for the video.
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(#"No groups");
}];
[library release];
This example is in the AVFoundation Programming guide, more details on the Apple developer website
I have made the same project for one of my client. I can tell you the idea but cann't tell you the code. The idea is while taking or saving video take the starting frame of every video and save it as PNG image as icon of the video. By this way you will get the icon of every video. Save all the Images in different folder in such a manner that each image can be link with its video. Now retrieve all videos from the document folder by below code
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
filelist = [filemgr contentsOfDirectoryAtPath:path error:nil];
*filelist is the NSArray
In the same manner retrieve the icons of the videos.
Make a grid view of buttons. Set images of the buttons as icons of the videos. Show the video names. When click on the video open a new view controller and make a video player ther play the video there.
I want to develop an iOS application where i want to get any PDF/Doc/XLS file present in my Mail/Safari by using UIDocumentInteractionController and finally upload them to my local server.
I can able to upload image file present in my iPhone to my local server.
But my question is, can i able to fetch PDF/Doc/XLS file(present in safari/ Mail application) to my application by using UIDocumentInteractionController & upload them to my local server?
It is indeed possible to Import a file from another application using UIDocumentInteractionController in case of an iPad app. All you need to do is in info.plist of you application you need to add supported document formats. Add applicationDidFinshWithLaunchingOptions delegate method to your app in application delegate class in the following manner.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self applicationDidFinishLaunching:application];
if (launchOptions && [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey])
{
NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSURL *url=[launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString *sourceFilePath=[url path];
NSFileManager *fileManager=[NSFileManager defaultManager];
NSData *fileData=[fileManager contentsAtPath:sourceFilePath];
NSString *fileName = [NSString stringWithFormat:#"test.pdf"];
NSString *updatedFilePath = [path stringByAppendingPathComponent:fileName];
BOOL hasWrittenSuccessfully = [fileData writeToFile:updatedFilePath atomically:TRUE];
}
return YES;
}
You can't fetch documents, you can tell iOS that your app can open PDF/Doc/XLS.
Do this by adding supported filetype to you info.plist:
http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html#//apple_ref/doc/uid/TP40010411-SW1