Documents/Images display fine in Simulator, but not on my device - iphone

My application is running fine on the simulator, but not on the device. Basically, any documents from the web (PDF, Word, M4P videos) are working great on the simulator (and can be accessed from Safari on the iPhone). However, running on the iPhone, they don't display anything. Here's some sample code:
// Set up the URL
documentViewController.documentUrl = [NSURL URLWithString:[NSString stringWithFormat:mobileContentUrl]];
// mobileContentUrl is something like: http://www.myserver.com/pathitem/Video.mp4" and can be accessed from Safari
[self.navigationController pushViewController:documentViewController animated:YES];
Within documentViewController I have:
- (void)viewDidLoad {
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:documentUrl]];
}
As I said, works like a charm in the Simulator...What could possibly causing this NOT to work on iPhone? How do I debug the issue???

The most likely cause is that you're trying to load a format that isn't supported by the phone. The Simulator uses many libraries from the Mac, so it often has much greater support than is available on the phone.
Can you access these URLs using MobileSafari on the phone?

PDF should work on the iPhone, as long as it doesn't require too much memory to display. The Simulator has pretty much unlimited memory while the iPhone is limited by the hardware, which I'm not sure but I think you have about 32 MB to play with on the oldest iPhones.
I'm not sure about the other formats. When you wrote M4P, did you mean mp4, or do you really mean M4P, because that is a protected AAC file that the iTunes Music Store uses, and you can't play those except through certain methods that enforce copy protection.

Related

Video searching

I'm developing app for IPhones where users clicks button, gets the list of all videos from his IPhone and uploads chosen video to server.
I know how to upload video to server, but I don't know how to implement video searching.
How can I get pathes to all videos (in users IPhone) in Array?
(Currently my IPhone is unavailable for use, so I'd like to know also how to test video search in IPhone Simulator?)
Kind Regards
You need to use the UIImagePickerController component, configuring it to show only videos when browsing the library.
You can do that by setting the mediaTypes property of the picker in this way:
myImagePickerController.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
Then if you want to test it in the simulator, you need to save some videos on it and you can use the UISaveVideoAtPathToSavedPhotosAlbum function to achieve that. Check out this great answer for more detailed instructions.
This link shows how to access only videos from the photoroll since all videos of the device should be stored there, you should be able to access them from there: Picking video from PhotoLibrary with UIImagePickerController in OS 3.1

Saved video to server from iPhone wont play back via URL in MPMovieVideoController

I have saved a video file at medium quality from the iPhone to Google App Engine. The video plays back fine on the web using the given URL.
http://www.getsplash.com/t/video/wa6Rbzq74WOB
This file will not play back on iPhone, I just get a black screen. I've been able to play other .mov sample files from the web just fine so its not the Objective-C as far as I know. I'm wondering if the encoding that the iPhone stores the video at is not compatible with pulling it back in via a URL?
I've tried adding an extension to the URL above and changing the content type to video/quicktime to no avail.
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://www.getsplash.com/t/video/wa6Rbzq74WOB"]];
moviePlayerController.view.frame = CGRectMake(0, 51, 320, 240);
[scrollView addSubview:moviePlayerController.view];
[moviePlayerController play]
Putting the answer here. The solution turned out to be adding ".m4v" to the end of the file URL and that enabled the MoviePlayerController to play it back. I thought relying on file extensions alone was a windows downfall, not something Apple relied on. We also ended up moving from Google Cloud Storage to AWS which has many more controls for types and security.
What exact model of iPhone are you testing on? The video is encoded with the Baseline 3.0 profile, which won't work on older models like the 3 and 3GS, I believe.

iOS Video: More than 4 simultaneous AVAssetReaders possible?

I would like to render multiple H264 mp4 videos on multiple views at the same time. Target is to read about 8 short videos, each at a size of 100x100 pixels and let them display their content on multiple positions on the screen, simultaneously.
Imagine 24 squares on the screen, each showing one video out of pool of 8 videos.
MoviePlayer doesn't work, for it's only showing one fullscreen video. An AVPlayer with multiple AVPlayerLayers is limited, because only the most-recently-created Layer will show it's content on screen (according to the documentation and my testing).
So, i wrote a short video class and created an instance for every .mp4 file in my package, using AVAssetReader to read it's content. On update, every videoframe is retreived converted to an UIImage and displayed, according to the video's framerate. Furthermore, these images are cached for a fast access on looping.
- (id) initWithAsset:(AVURLAsset*)asset withTrack:(AVAssetTrack*)track
{
self = [super init];
if (self)
{
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA], (NSString*)kCVPixelBufferPixelFormatTypeKey, nil];
mOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:track outputSettings:settings];
mReader = [[AVAssetReader alloc] initWithAsset:asset error:nil];
[mReader addOutput:mOutput];
BOOL status = [mReader startReading];
}
return self;
}
- (void) update:(double)elapsed
{
CMSampleBufferRef buffer = [mOutput copyNextSampleBuffer];
if (buffer)
{
UIImage* image = [self imageFromSampleBuffer:sampleBuffer];
}
[...]
}
Actually this works pretty well, but only for 4 videos. The fifth one never shows up. First I thought of memory issues, but I tested it on the following devices:
iPhone 3GS
iPhone 4
iPad
iPad 2
I had the same behaviour on each device: 4 videos playing in a smooth loop, no differences.
If it would have been a memory issue, I would have expect at least either the iPad 2 to show 5 or 6 videos (due to it's better hardware) or the 3GS to show only 1 or a crash somewhere.
The simulator shows all videos, though.
Debugging on the device shows, that
BOOL status = [mReader startReading];
returns false for video 5,6,7 and 8.
So, is there some kind of hardware setting (or restriction) that doesn't allow more than 4 simultaneous AVAssetReaders? Because, I can't really explain this behaviour. I don't think that all devices have the exact same amount of video memory.
Yes, iOS has an upper limit on the number of videos that can be decoded at one time. While your approach is good, I don't know of any way to work around this upper limit as far as having that many h.264 decoders active at once. If you are interested, please have a look at my solution to this problem, this is an xcode project called Fireworks. Basically, this demo shows decoding a bunch of alpha channel videos to disk, then each one is played by mapping a portion of the video files into memory. This approach makes it possible to decode more than 4 movies at the same time without using up all the system memory and without running into the hard limit of the number of h.264 decoder objects.
Have you tried creating separate AVPlayerItems based on the same AVAsset for each AVPlayerLayer?
Here's my latest iteration of a perfectly smooth-scrolling collection view with real-time video previews (up to 16 at a time):
https://youtu.be/7QlaO7WxjGg
It even uses a cover flow custom layout and "reflection" view that mirrors the video preview perfectly. The source code is here:
http://www.mediafire.com/download/ivecygnlhqxwynr/VideoWallCollectionView.zip

How to silence iPhone camera shutter sound?

I can snap a picture with the iPhone programmatically by calling [UIImagePickerController takePicture:], but when I do the iPhone plays a loud recording of a shutter click. When I google for how to turn off the click, I find advice to rename the sound file that the iPhone plays. It seems to me for my app to do that would lead to it being rejected from the App store for accessing system frameworks. Is there a programmatic way to shut off that sound? The nature of my app demands that the camera be silent.
I assume you have solved it since but your app supposed to fail on the Appstore validation as it doesn't comply with iOS Dev License agreement. See below:
Section 3.3.8: Any form of user or device data collection, or image,
picture or voice capture or recording (collectively "Recordings"), and
any form of data, content or information collection, processing,
maintenance, uploading, syncing, storage, transmission, sharing,
disclosure or use performed by, through or in connection with Your
Application must comply with all applicable privacy laws and
regulations as well as any related Program Requirements, including but
not limited to any notice or consent requirements. In particular, a
reasonably conspicuous audio, visual or other indicator must be
displayed to the user as part of the Application to indicate that a
Recording is taking place.
Not sure if you would want to do it...
The sound is there to let someone know a photo is being taken. The idea is to ensure privacy and safety of the public, especially children," something that Japan has already required of their snap-happy citizens
Japan and Korea already have laws that require this sound when taking pictures.
http://abcnews.go.com/Technology/story?id=6750825&page=1
excerpt:
"In Japan and Korea, Segan pointed out, in response to mounting reports of "underskirting," governments have passed laws similar to the one King proposes."
Renaming the sound file wouldn't be using a "private API"; it's simply not possible from within the sandbox (assuming you haven't broken out of the sandbox somehow).
However, on 4.0+, you can use AVCapture to take pictures instead. I'm not sure if AVCaptureStillImageOutput plays a shutter sound; a workaround is to use video frames.
I have to wonder what you mean by "the nature of my app" though. If you're trying to do some sort of live image processing, then video frames are a much better way to go in the first place. If you're trying to take pictures silently with the user's permission, then the user should be able to silence the shutter sound anyway. If you're trying to take pictures without the user's permission, you're probably violating some agreement with Apple.
For what it's worth, I was able to get this to work by using this code in the snapStillImage method of AVCapture framework using AVCaptureStillImageOutput. It works perfectly for me on iOS 8.3 iPhone 5. I have also confirmed that Apple won't reject your app if you use this:
MPVolumeView* volumeView = [[MPVolumeView alloc] init];
//find the volumeSlider
UISlider* volumeViewSlider = nil;
for (UIView *view in [volumeView subviews]){
if ([view.class.description isEqualToString:#"MPVolumeSlider"]){
volumeViewSlider = (UISlider*)view;
break;
}
}
[volumeViewSlider setValue:0.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
Swift 4:
var volumeView = MPVolumeView()
//find the volumeSlider
var volumeViewSlider: UISlider? = nil
for view: UIView in volumeView.subviews {
if (view.self.description == "MPVolumeSlider") {
volumeViewSlider = view as? UISlider
break
}
}
volumeViewSlider?.setValue(0.0, animated: true)
volumeViewSlider?.sendActions(for: .touchUpInside)

How do I test a camera in the iPhone simulator?

Is there any way to test the iPhone camera in the simulator without having to deploy on a device? This seems awfully tedious.
There are a number of device specific features that you have to test on the device, but it's no harder than using the simulator. Just build a debug target for the device and leave it attached to the computer.
List of actions that require an actual device:
the actual phone
the camera
the accelerometer
real GPS data
the compass
vibration
push notifications...
I needed to test some custom overlays for photos. The overlays needed to be adjusted based on the size/resolution of the image.
I approached this in a way that was similar to the suggestion from Stefan, I decided to code up a "dummy" camera response.
When the simulator is running I execute this dummy code instead of the standard "captureStillImageAsynchronouslyFromConnection".
In this dummy code, I build up a "black photo" of the necessary resolution and then send it through the pipelined to be treated like a normal photo. Essentially providing the feel of a very fast camera.
CGSize sz = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) ? CGSizeMake(2448, 3264) : CGSizeMake(3264, 2448);
UIGraphicsBeginImageContextWithOptions(sz, YES, 1);
[[UIColor blackColor] setFill];
UIRectFill(CGRectMake(0, 0, sz.width, sz.height));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
The image above is equivalent to a 8MP photos that most of the current day devices send out. Obviously to test other resolutions you would change the size.
I never tried it, but you can give it a try!
iCimulator
Nope (unless they've added a way to do it in 3.2, haven't checked yet).
I wrote a replacement view to use in debug mode. It implements the same API and makes the same delegate callbacks. In my case I made it return a random image from my test set. Pretty trivial to write.
A common reason for the need of accessing the camera is to make screenshots for the AppStore.
Since the camera is not available in the simulator, a good trick ( the only one I know ) is to resize your view at the size you need, just the time to take the screenshots. You will crop them later.
Sure, you need to have the device with the bigger screen available.
The iPad is perfect to test layouts and make snapshots for all devices.
Screenshots for iPhone6+ will have to be stretched a little ( scaled by 1,078125 - Not a big deal… )
Good link to a iOS Devices resolutions quick ref : http://www.iosres.com/
Edit : In a recent project, where a custom camera view controller is used, I have replaced the AVPreview by an UIImageView in a target that I only use to run in the simulator. This way I can automate screenshots for iTunesConnect upload. Note that camera control buttons are not in an overlay, but in a view over the camera preview.
The #Craig answer below describes another method that I found quite smart - It also works with camera overlay, contrarily to mine.
Just found a repo on git that helps Simulate camera functions on iOS Simulator with images, videos, or your MacBook Camera.
Repo