Video Array in iOS 5 and using MPMoviePlayerController possible? - arrays

I am trying to implement a set of videos ont his app I am developing, but since I am not an experienced developer I came here to as the help of others.
Well, the app is a simple PS3 games database for iPad using splitView. On the Master I have a tableview with the titles and on the details I have the game cover and two buttons: one for the info on the game (that loads another view) and the other one to load a demo video of the respective game.
As you might know, I created an array to store the name of the games, the filename of the cover image and the description.
So, when I click on the master row for, example Assassin´s Creed II, on the detail view will show the corresponding cover and clicking the info button will show me a brief description of the game.
But the problem is that I don´t know how I can add the video the same way I did with the image..
I managed to play the video using the MPMoviePLayerController, but I had to specify the video, but since I am working with storyboard, and working with just the header and implementation files of the master and detail, as far as I know (or I don´t know at all) I can´t use MPMoviePLayerController class to every video.
So, I ask, is it possible to create a video array and work the same way I did with the cover images???
Thank you in advance,
Marco Almeida.

The solution:
NSString *nomeArquivo = [atualJogo movie];
NSString *Arquivo = [nomeArquivo stringByDeletingPathExtension];
NSString *extension = [nomeArquivo pathExtension];
[video loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:Arquivo ofType:extension]isDirectory:NO]]];

Did you try this?
myVideos = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"myvideo_01"],
[UIImage imageNamed:#"myvideo_02"],
[UIImage imageNamed:#"myvideo_03"],
[UIImage imageNamed:#"myvideo_04"],
[UIImage imageNamed:#"myvideo_05"],
nil];

Related

How would I go about encoding a video from an array of images like a time-lapse?

So I have been trying to do this for ages with no luck, ive found some solutions on git hub but these arent working for me, basically I have an array of UIImage which I want to be converted into a 10 second long video when the user presses a button, this video will then be saved to the users camera roll, does anyone have any code to deal with this in swift?
EDIT: The question which this has been marked as a duplicate from is answered in objective c, not swift

videoangular--How to have multiple video players in one screen?

Hi so Im using this angularjs framework "videogular" and have no problem creating a single player, but I dont know how to create multiple players in one screen since apparently each player requires a controller
sample code here:
http://codepen.io/2fdevs/pen/KmDIE
Each player needs a different config file but not a different controller.
Maybe this other answer could be useful:
stop other video that is playing in background on play the new one

How to download images from array to tableviewcontroller in swift?

I have a table view controller with a cell that contains an UIImageView. I also have a NSMutableArray that contains the url's. I want the url's to download the images and place them in the correct order. The NSMutableArray also contains some empty Strings and the cell that it corresponds too I want to have my placeholder image from my image assets.
How can I get it to work? I have also populated each cell with a title and summary but cannot workout how images work.
UPDATE
The code used for the image download. Note the photoLabels contains the array of images. Some of the photos are in the incorrect place once the first placeholder image occurs (It is one index late). Why is it doing that. Does anyone know why. I have println(photoLabels) and all the 50 strings are correct (with some just being "")
If anyone can help that would be great.
let imageURL: String = photoLabels.objectAtIndex(indexPath.row) as String
println(imageURL)
if imageURL == "" {
cell.imageContainer.image = UIImage(named: "placeholder")
} else {
cell.imageContainer.setImageWithURL(NSURL(string: imageURL))
}
return cell
Thanks
This seemingly innocent question actually entails a rat's nest of interesting details. These include:
Use lazy loading of the image, loading them just-in-time, rather than trying to download them up front;
Download the images asynchronously;
While downloading the images as needed, cache them (using NSCache, not NSMutableArray) so that if you scroll back to see some images recently downloaded that you don't have to download them again;
But, in response to memory pressure, make sure to empty the RAM-based cache (but still avail yourself of the persistent storage cache);
If user scrolls quickly down to the 100th row in the table example, make sure that the images for the visible cells don't get backlogged behind the requests for the previous 99 images (nb: you should test your app in suboptimal conditions, e.g. a poor 2G or 3G cellular environment, which can be simulated with the network link conditioner); and
You might want a placeholder image to show until the asynchronously retrieved image is downloaded (or retrieved from the cache).
The bottom line is that this takes a non-trivial amount of effort to do properly. As a result, I'd encourage you to use an existing solution, for example the UIImageView categories that are available from SDWebImage or AFNetworking. Both of these two frameworks offer a nice category for UIImageView that allows you to request the image to be downloaded asynchronously (it's sd_setImageWithURL in SDWebImage; it's setImageWithURL in AFNetworking).

Xcode / iOS6 / UIWebView URL / HTML links do not work

After looking through numerous Stack Overflow posts, I was unable to find a solution to my problem. If I am asking a question that has already been answered elsewhere, kindly give me a nod in the right direction.
And, please, don't be too harsh on me if I might be using the wrong terminology, as I am still kind of new to mobile development.
Problem: All I am trying to do is click a link in a local web page that gets pulled up in a UIWebView. Currently, nothing happens when I click a link, aside from a brief flash of the current page.
This is where I'm at:
1) When the application loads, I show a web view which displays a "local" web page (that's part of my xcode project). So far, so good.
2) When the end user clicks an item (geographical regions in my case, represented by a flag), additional content becomes visible, including a couple of links, leading to "external" web apges, such as wikipedia and a map web site.
3) Most of my little web app is in the web page I show when the application has loaded. I use JavaScript, HTML and CSS to provide most of the functionality (since I already have a web site that does exactly what it is supposed to do).
4) However, being able to link to other web sites from my start page is crucial.
(If you think this is poor design, I'll accept that. Suggestions for better approaches are always welcome; HOWEVER, I do need to solve my current problem before I can restructure my code. Please bear with me.)
Here's the code that brings up the initial web page:
// View Controller.h
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIWebView *spfWebView;
#end
// ViewController.m
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize spfWebView;
- (void)viewDidLoad{
[super viewDidLoad];
//Web Site within XCode Project:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"www/index" ofType:#"html"] isDirectory:NO];
//NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ( [data length] > 0 && error == nil ){
[spfWebView loadRequest:request];
}else if (error != nil){
NSLog(#"Error: %#", error);
}
}];
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
So in my web page, I am using standard, normal a href links to point to wikipedia, for example, like so (I had to use spaces in the href part to avoid SO from interpreting it as a link, since I only wanted to show you the code for the link):
Wikipedia
And, as I've mentioned, the page just sits there when I click or tap the link. The page seems to reload briefly and flashes on the screen, but that's all I see.
Any ideas anyone?
After additional searching and finally finding some really great information here on SO and a couple of external links, I now see how naive my original question was. It turns out there is more to it than meets the eye.
I wanted a quick fix for a problem that requires a bit more work than I realized.
The most important things I have learned are:
(1) A UIWebView is not necessarily the same as a web browser.
(2) In a UIWebView, you can display web content, yes, but you have to address page clicks separately, within XCode.
(3) If you are planing on running your web app on HTML5, CSS3 and JavaScript, inside a UIWebView, you can do a lot, but you might have to learn about making the UIWebView a delegate to itself, opening additional views, etc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The lessons I have learned come primarily from the following sources:
Clicking a link in UIWebView pushes onto the NavigationView stack
iPhone UIWebView - Open new UIWebView Controller from a hyperlink
UIWebView Link Click
Calling methods from links in a UIWebView
Open a link in a UIWebView
Open iOS6 Apple Maps app from a link in a UIWebView
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So right now, I am refactoring my little phone app, but if anyone has some additional insights as far as making UIWebView links work (in an easy and up-to-date manner), please add your comments, and I will try and implement them into this post.

How to get iOS resource dictionary from resource path for current language?

I have an iPad app (XCode 4.6, iOS 6.2, Storyboards and ARC). I am trying to localize a UISegmentControl. I already have the translations in MainStoryboard.strings file, and have this code in the controller's viewDidLoad:
// set titles of UISegmentedControls
NSString *resourcePath =[[NSBundle mainBundle] pathForResource:#"MainStoryboard" ofType:#"strings"];
NSDictionary *resourceDict = [NSDictionary dictionaryWithContentsOfFile:resourcePath];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:#"jcy-vN-Nq9.segmentTitles[0]"] forSegmentAtIndex:0];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:#"jcy-vN-Nq9.segmentTitles[1]"] forSegmentAtIndex:1];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:#"jcy-vN-Nq9.segmentTitles[2]"] forSegmentAtIndex:2];
The problem is that both resourcePath and resourceDict are nil. How do I get them for the current language, be it en or some other language?
Don't do any of that. You localize the storyboard by editing the .strings file that goes with it for the appropriate language. When iOS displays the view, it'll automatically grab the proper localization and display it.
EDIT: If you want to pull something from the strings file, do something like this:
[[NSBundle mainBundle] localizedStringForKey:#"someKeyHere" value:nil table:#"MainStoryboard"];
Since UISegmentedControls can't have their title localized, I replaced them with RadioButtons I got from GitHub; localized the labels, moved the radio buttons next to them and it works like a champ.
UPDATE One problem - there doesn't appear to be any way to persist the settings from run to run, therefore, this is not going to work. I am now creating my own custom button and emulating a UISegmentedControl. Works with no problems...

Resources