UIVideoAtPathIsCompatibleWithSavedPhotosAlbum returns false when deploying on the iPhone - objective-c

One of my app's features is to download a mp4 file and store it to the local phone album.
I have tried several approaches since and the result is always the same, it worked on the simulator but not on the actual iPhone. Xcode is version 5.0.1, iPhone 4.
Below is the code I applied on the last attempt before posted here using ASIHttpRequest library and the result is still the same, it worked on the simulator but not the phone itself.
download:
ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url]; // url is the address to the mp4 file
NSString* filePath = [NSString stringWithFormat:#"%#%#", NSTemporaryDirectory(), filename]; //filename is the file I save to, e.g. xxx.mp4
[request setDownloadDestinationPath:filePath];
[request setDelegate:self];
[request setDidFinishSelector:#selector[ASIRequestDone:)];
[request setDidFailSelector:#select[ASIRequestFail:)];
when download is finished, save it to the photo album (in ASIRequestDone delegate)
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath))
{
//comes to here when running in simulators
UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, #selector(video:didFinishSavingWithError:cotextInfo:),nil);
}
else
{
//always comes to here when running on the actual iPhone.
}
I have checked the pathFile it's this
/private/var/mobile/Applications/xxxxxxxxxx/tmp/xxxxx.mp4
which is alright to me. What I am not getting is it works fine when running on Simulator and hence I am stuck not sure what to do next. (I have also checked the permission accessing the the photo albums and yes the app has it).
I also tried to removed the compatible checking and went straight into the method UISaveVideoAtPathToSavedPhotosAlbum, it didn't throw any error on delegate didFinishSavingWithError. however, the video didn't show up on the photo album either, I am guessing it's correct as the phone seems to say that video is not compatible to be shown on the album. Again, my issue is that it does work on the simulator and how do I fix this on the actual iphone, e.g. why it thinks the video is not compatible? is something to do with the mp4 itself or is it something to do during the download step? What could I do next to resolve the issue? (ps. I also have control over the mp4 files, is there a list of mp4 compatibility on the iphone that you know? I am thinking perhaps it's genuine that the file is not compatible on the phone (but on the simulator!?))

Found the answer to my question and I hope it could help out someone who suffers from the same issue. Turns out video resolution is the factor between the simulator and the actual phone when it comes to store video to the gallery; to be specific:
Compatibility checking UIVideoAtPathIsCompatibleWithSavedPhotosAlbum would FAIL on the actual phone but would PASS on the simulator given a sample clip capturrd as 1080p. I came cross this link a week after my post with luck.
"What video formats are compatible with the assets library?"
And I did the experiment similar to that by capturing 720p video clips instead and all files were able to be saved to the gallery. Weird thing is that the actual iphone can play the HLS stream at 1080p; howeve it won't store clips unless they are 720p, not to me anyway. And the misleading bit is that the simulator can actually do 1080p.

Related

Capture screen and audio with objective-c

I'm using an AVCaptureSession to create a screen recording (OSX), but i'd also like to add the computer audio to it (not the microphone, but anything that's playing through the speakers) i'm not really sure how to do that so the first thing i tried was adding an audio device like so:
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
After adding this device the audio was recorded, but it sounded like it was captured through the microphone. Is it possible to actually capture the computer's output sound this way? like quicktime does.
Here's an open source framework that supposedly makes it as easy to capture speaker output as it is a screenshot.
https://github.com/pje/WavTap
The home page for WavTap does mention that it requires kernel extension signing privileges to run under MacOS 10.10 & newer, and that requires signing into your Apple Developer Account and submitting this form. More information can be found here.

iOS 6 - UIWebView loadHTMLString not working properly

If anyone experienced the issue below, please let me know if you were able to find a fix. I've spent a couple of days trying to come up with a solution, but no luck so far. I'm using XCode 4.5 with iOS 6 SDK Golden Master.
Basically, my application reads and HTML file and hands its contents to a web view for rendering.
NSString *path = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"html"];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
NSURL *baseURL = [NSURL URLWithString:#"http://mysite.com"];
[webView loadHTMLString:html baseURL:baseURL];
The HTML contains a few <link> tags, for instance:
<link href="/webshare/accounts/maxk/styles/mobile_app_iphone_article.css?1312306173" media="screen" rel="stylesheet" type="text/css" />
The problem is, UIWebView seems to have troubles downloading the CSS file. The UIWebViewDelegate does receive webViewDidStartLoad right away, but it takes about 5 minutes before it receives webViewDidFinishLoad message. CSS is not picked up.
If I remove the link from HTML, everything works normally.
I had a similar issue in my web views once iOS 6 came out. Try setting the following UIWebView property to true (YES) { only available in iOS 6+ }:
suppressesIncrementalRendering
A Boolean value indicating whether the web view suppresses content rendering until it is
fully loaded into memory.
#property(nonatomic) BOOL suppressesIncrementalRendering
Basically in my circumstances the async content loading created a bit of an odd race condition that wasn't there before. Took me a while to find that one. I also agree with Brian though -- use some proxy software and watch your traffic to verify everything you need is coming in and when it comes in. That can be very useful.
Let me know if it helps?
Without having direct access to the project, it's really hard to say. Have you tried to loading the page in a local browser to confirm that the css is indeed being loaded? If it is loading, then I'd suggest running the app in the simulator while also running something like Charles proxy. Charles will record all of your outbound requests and display the results of them. That way, you can determine whether the issue is truly internal or external to the sdk.
If you do have an apple developer account, check out WWDC 2012 Session videos. You can find them here: https://developer.apple.com/videos/wwdc/2012/. There is one video titled, "Debugging UIWebViews and Websites on iOS". I haven't watched it yet, but it may contain some info that will help you resolve the issue.
Good luck!
So if the all css and other stuff is on remote server, why do you load html from the local file? Probably this is something security related (you are trying to load html from the local file while other stuff from remote), or just problem with handling of baseURL in UIWebView

AVFoundation Record Video for web playback -- has to download WHOLE file before playback starts

I have an iPad app that records video and sends it to my SaaS application using AVFoundation. My web application then reads the file, and plays it using JWPlayer.
The problem I am having, is that JWPlayer (or any player I have tried) has to download the WHOLE video file before it will play. After doing some reading, I have discovered that the videos recorded from IOS don't have "fast start from internet" enabled. Or something along those lines.
I am using AVFoundation. Is there a different way to save the video so it will stream instantly from my web server? What am I missing.
The shouldOptimizeForNetworkUse property on AVWriter allows you to do this.
You could use it to rewrite the captured movie file prior to uploading to your server (or immediately post-capture, whatever suits I suppose).
Edit:
Okay, I'm not at a Mac at the moment, but something along these lines:
AVAsset *originalFile = [AVAsset assetWithURL:originalFileURL];
NSURL *outputFileURL = wherever you want to put it;
NSError *readerError;
NSError *writerError;
AVAssetReader *reader = [AVAssetReader assetReaderWithAsset:originalFile error:&readerError];
AVAssetWriter *writer = [AVAssetWriter assetWriterWithURL:outputFileURL fileType:AVFileTypeQuickTimeMovie error:&writerError];
writer.shouldOptimizeForNetworkUse = YES;
[writer startWriting];
...
and so on.

iTunes Match + AVplayer + MPMediaQuery not working

I'm developing an app which makes usage of AVPlayer, MPMediaItem and MPMediaQuery. It works as long as Itunes match. We start with a MPMediaQuery, then we perform some filtering leaving some MPMediaItems, then we have been using AVPlayer because:
1.- we also play noises during the song play
2.- we need to suscribe to play/stops events from ipod.
All this features are currently working, except if the ipod library has itunes match enabled. Even when AVPlayer status is playing, no sound comes. Is obvious that it is not triggering the song download from iCloud.
All the information I have about itunes match by the moment is this post:
MPMediaItem and iTunes Match
which states you can trigger the download by using a MPMusicPlayerController play call. For the reasons given above, we cannot make use of this class to control our own player.
I have two ideas on how to solve this problem:
A. Find a way to check if a song is already downloaded and available in the library to play using AVPlayer. If the song is not available let the user know that we don't support songs not available.
B. Find a way to trigger the download of the song just before it becomes the next item to play.
I still cannot find how to implement any of these solutions and I haven't found any related documentation, so I submitted my app with a warning message to prevent users to use this app if they are using itunes match.
On iOS 6 and up you can use [[item valueForProperty:MPMediaItemPropertyIsCloudItem] boolValue] to check if an item is already downloaded.
A. Find a way to check if a song is already downloaded and available
in the library to play using AVPlayer. If the song is not available
let the user know that we don't support songs not available.
This isn't perfect but it works in most cases. Songs downloaded from iTunes Match will be DRM free. So you can check the assets DRM flags, if it is not exportable then it needs to be downloaded. It is possible to get a false positive with audio books/pod casts but you are mostly safe.
MPMediaItem* item
NSURL* url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset* assetToLoad = [[AVURLAsset alloc] initWithURL:url options:nil];
bool protectedCon = assetToLoad.hasProtectedContent;
bool exportable = true;
if (gApp.mSysVersionInt >= 5) {
exportable = assetToLoad.exportable; //4.3+
}
B. Find a way to trigger the download of the song just before it
becomes the next item to play.
You can try doing this will a muted MPMusicPlayerController, but there is no way to track when the song is downloaded and sometimes it takes a very long time.

Objective-C iPhone - YouTubePlugIn.webplugin/YouTubePlugIn warning

I'm trying to play a YouTube video within an iPhone app using the technique in this URL
http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
The technique works fine and the video plays fine, except that I'm getting this warning.
warning: Unable to read symbols for "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2 (7D11)/Symbols/System/Library/Internet Plug-Ins/YouTubePlugIn.webplugin/YouTubePlugIn" (file not found).
That does slow down the app for the first time I got the warning. Seems like a lot of people is getting the same warning, but none of the forums I read seems to have the solution to get rid of the warning.
Do I need to download something or do specific things?
I also tried adding the YouTube framework from "/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/System/Library/PrivateFrameworks/YouTube.framework"
Doesn't seem to solve the issue.
Please enlight.
Some clips might not play in mobile devices. Check if you clips does.
The "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/usr/lib/dyld' has changed; re-reading symbols" warnings can be ignored (the clips should play anyway if it is available on mobile devices).
Note. I don't know the correct reason why some clips don't play on mobile, it might be a transcoding issue (not being transcoded for mobile) or some publisher settings.
Would be interesting to know.
You need to run your app on the device. The Simulator doesn't have the YouTube app.