PSYouTubeExtractor Error while Extraction - objective-c

I am trying to use the PSYouTubeExtractor in my Project, it is supposed to help with displaying YouTube videos inline by either downloading the mp4 or displaying it in a web view.
Here is how I implemented it so far:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[PSYouTubeExtractor extractorForYouTubeURL:[deskUrls objectAtIndex:indexPath.row] success:^(NSURL *URL) {
NSLog(#"Finished extracting: %#", URL);
// show the movie!
} failure:^(NSError *error) {
NSLog(#"Failed to query mp4: %#", error);
}];
}
deskUrl is: this link for example and while this is extracting an error occurs:
[PSYouTubeExtractor doRetry_] [Line 105] Trying to load page...
2012-09-30 17:50:40.054 Tube[3378:907] -[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x21027eb0
Well, I do not understand why, because this is just how it should be done. On the github page of the developer here, this is just the same code.
Anyone has an idea how to fix this?

It expects a NSURL instance but you obviously are providing an NSString instance.
Convert your string into a URL using the following call;
NSURL *youTubeURL = [NSURL URLWithString:[deskUrls objectAtIndex:indexPath.row]];
Then you may use the extractor factory/singleton as already done in your example;
[PSYouTubeExtractor extractorForYouTubeURL:youTubeURL success:^(NSURL *URL) {
NSLog(#"Finished extracting: %#", URL);
// show the movie!
} failure:^(NSError *error) {
NSLog(#"Failed to query mp4: %#", error);
}];

Related

Unable to download and view images from parse in iOS

As of yesterday I was able to view images fine but now I can't view from url and get error as
NSErrorFailingURLKey=http://files.parsetfss.com
Some images are working fine while others are getting issues.
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:objStampData.stampImage.url] placeholderImage:[UIImage imageNamed:#"PlaceHolder.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
if(!error)
{
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
}
else
{
NSLog(#"Error %#",error);
}
}];
Two possible reasons:
Name of the image in parse. There I have problem when the name contains somestrange symbols like ".","&" and etc. Try with simple name and different image format.
Check if you allow
access to parse from the plist file check here

Array of image url to ui collectionview

I am doing a json query to get an array of image urls. I want to display the images on a uicollection view. But I am missing something. I think I have to parse thru the array and set nsurl to each item. Then put each item in nsdata. But I am not sure. I don't want to use 3rd party software either.
Here is a sample of my code.
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
coProFeedURL];
[self performSelectorOnMainThread:#selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
}
///new return all company data array
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray * getProductsArray = [json objectForKey:#"CompanyProduct"]; //2 get all product info
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"companyID = %#", passCoData];//added create filter to only selected company
NSArray * filteredProductArray = [getProductsArray filteredArrayUsingPredicate:predicate];//only products for selected company
///doing parsing here to get array of image urls
finalImageArray = [filteredProductArray allObjects];//original
NSLog(#" url images :%#", finalImageArray);
//NEED TO GET FINALIMAGEARRAY TO NSURL TYPE AND SET TO IMAGE?
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return finalImageArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"Cell";//test form file works
ItemCollectionViewCell *cell = (ItemCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];//test form file works
///then add the finalImageArray?
return cell;
}
Here the output of my finalImageArray that i want to apply to uicollectionview, here is the log data:
{(
"http://www.test/inventory/images/bball.jpg",
"http://www.test/images/bird%20tank_0.jpg"
)}
So am i missing something like nsurl, or nsdata, or what. How do i get this array of image url to display on a uicollectionview? Thanks for the help!
Just reload Collection view with updated data of array. As you requested on background thread. Now, you need to reload data on main thread.
- (void)fetchedData:(NSData *)responseData {
//YOUR CODE ...
finalImageArray = [filteredProductArray allObjects];//original
NSLog(#" url images :%#", finalImageArray);
//NEED TO GET FINALIMAGEARRAY TO NSURL TYPE AND SET TO IMAGE?
dispatch_async(dispatch_get_main_queue(), ^{
[collectionView reloadData];
});
}
Hope, it'll help you.

Save Video into Custom Album iOS

How to save video with my custom album .
I found one link but it don't work Custom file manager
It gives the url value is null.
[VideoAlbumManager addVideoWithAssetURL:outputFileUrl toAlbumWithName:#"Video Maker"];//outputfileurl is my video url from document directory
Give any suggestion for this..
-(void)SaveToalbum{
NSString *finalFileName=[NSString stringWithFormat:#"Documents/video.mov"];
NSString *videoOutputPath = [NSHomeDirectory()
stringByAppendingPathComponent:finalFileName];
NSString* webStringURL = [videoOutputPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url =[NSURL URLWithString:webStringURL];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:url])
{
NSURL *clipURl = url;
[library writeVideoAtPathToSavedPhotosAlbum:clipURl completionBlock:^(NSURL *assetURL, NSError *error)
{
}];
}
}
You can try with it. It will be helpful for you. Just go through "http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/" link and download the sample project.
Drag-drop two file "ALAssetsLibrary+CustomPhotoAlbum.h" and "ALAssetsLibrary+CustomPhotoAlbum.m" into your project and add "AssetsLibrary.framework". Now you are ready for coding.Just go on your ViewController.h Class and import the <AssetsLibrary/AssetsLibrary.h> and "ALAssetsLibrary+CustomPhotoAlbum.h" file.
Create a object for ALAssetsLibrary and write a block for saving the video file in custom album,just like this,
[ALAssetsLibraryObject addAssetURL:clipURl toAlbum:AlbumName withCompletionBlock:^(NSError *error)
{
if (error!=nil) {
NSLog(#"Big error: %#", [error description])
}
}];
You can use this link to save the video..
GitHub Link
Import this two files into your project.
ALAssetsLibrary+CustomPhotoAlbum.h
ALAssetsLibrary+CustomPhotoAlbum.m
Then in your save IBAction method write this lines..
if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputFilePath)){
NSURL *muyrl=[NSURL fileURLWithPath:outputFilePath];
[library saveVideo:muyrl toAlbum:albumName withCompletionBlock:^(NSError *error)
{
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];
Where.. outputfilepath is your videopath and if you have url then save it with URL name.
library is ALAssetLibrary that define in .h file
albumName is your Album name what do you want..I hope this will help you.

Property text not found on object

I am a bit new to Xcode and Parse and am creating a query in a outlet collection. Everything looks fine except I am getting an error stating "Property 'text' not found on object of type 'id'"... Here is my code that I have:
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(#"Successfully retrieved %d scores.", objects.count);
// Do something with the found objects
int i = 0;
for (PFObject *object in objects) {
if (i >= [self.EventTitles count]) break;//to make sure we only write up to the max number of UILabels available in EventTitles
(UILabel *) self.EventTitles[i].text = object.objectId;//I assume the "objectId" property of object is an NSString!
i++;
}
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
Can anyone help me so I can get this build to not fail?
Change this:
(UILabel *) self.EventTitles[i].text = object.objectId;
to:
[(UILabel *)self.EventTitles[i] setText:object.objectId];

How do I use this block method?

I am a little bit confused about objective c programming with blocks.
for example Here is a method:
in the .h
- (void)downloadDataWithURLString:(NSString *)urlString
completionHandler:(void(^) (NSArray * response, NSError *error))completionHandler;
in the .m:
- (void)downloadedDataURLString:(NSString *)urlString
completionHandler:(void (^)(NSArray *, NSError *))completionHandler {
// some things get done here. But what!?
}
My main questions is.... how do I implement this completion handler? What variables would be returned with the array and error? it is one area for the code but how do I tell it what to do when it is completed?
It's up to the caller to supply code to be run by the method (the body of the block). It's up to the implementor to invoke that code.
To start with a simple example, say the caller just wanted you to form an array with the urlString and call back, then you would do this:
- (void)downloadedDataURLString:(NSString *)urlString
completionHandler:(void (^)(NSArray *, NSError *))completionHandler {
NSArray *callBackWithThis = #[urlString, #"Look ma, no hands"];
completionHandler(callBackWithThis, nil);
}
The caller would do this:
- (void)someMethodInTheSameClass {
// make an array
[self downloadedDataURLString:#"put me in an array"
completionHandler:^(NSArray *array, NSError *error) {
NSLog(#"called back with %#", array);
}];
}
The caller will log a two item array with #"put me in an array" and #"Look ma, no hands". In a more realistic example, say somebody asked you to call them back when you're finished downloading something:
- (void)downloadedDataURLString:(NSString *)urlString
completionHandler:(void (^)(NSArray *, NSError *))completionHandler {
// imagine your caller wants you to do a GET from a web api
// stripped down, that would look like this
// build a request
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// run it asynch
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (!error) {
// imagine that the api answers a JSON array. parse it
NSError *parseError;
id parse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&parseError];
// here's the part you care about: the completionHandler can be called like a function. the code the caller supplies will be run
if (!parseError) {
completionHandler(parse, nil);
} else {
NSLog(#"json parse error, error is %#", parseError);
completionHandler(nil, parseError);
}
} else {
NSLog(#"error making request %#", error);
completionHandler(nil, error);
}
}];
// remember, this launches the request and returns right away
// you are calling the block later, after the request has finished
}
While I can't be entirely sure without seeing any more details about the method, or its exact implementation I suspect this: this methods creates a new background thread, retrieves the data from the server and converts the JSON/XML to an NSArray response. If an error occurred, the error object contains a pointer to the NSError. After doing that, the completion handler is called on the main thread. The completion handler is the block in which you can specify which code should be executed after attempting to retrieve the data.
Here is some sample code on how to call this method to get you started:
[self downloadDataWithURLString:#"http://www.google.com"
completionHandler:^(NSArray *response, NSError *error) {
if (! error) {
// Do something awesome with the 'response' array
} else {
NSLog(#"An error occured while downloading data: %#", error);
}
}];