MPMoviePlayerController - catching network errors when loading a movie - mpmovieplayercontroller

Is there a way of catching exceptions (particularly for network errors
/ no connection available) when using a MPMoviePlayerController?
I am particularly concerned that once an instance of the player is initialised with initWithURL: you have no way of knowing whether the movie load has failed for some reason.
I have reviewed the available documentation and realise I can get a
notification for loadState changes through
moviePlayerLoadStateChanged:(NSNotification*)notification.
Problem is the loadState constants available don't cater for error handling:
MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled
(in case you are wondering, MPMovieLoadStateStalled this doesn't get called during network errors for some reason?)
There's a deprecated MPMoviePlayerContentPreloadDidFinishNotification that provides a userInfo dictionary with an "error" key but nothing for iOS 3.2 and above.
Any help would be very much appreciated.

In the end I got this sorted by subscribing to MPMoviePlayerPlaybackDidFinishNotification and watching for MPMovieFinishReasonPlaybackError.
More details here https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006953-CH3-SW17

Related

NativeScript Hybrid Mobile App: Tracking/Capturing Crashes

I am building a NativeScript mobile app and among other things I am capturing for analytics purposes, I need to capture "app crashes" possibly with errors/reasons it crashed.
I came across this SO post but there it was in the response of a question on how not to let the app crash. Following was suggested to catch crash events:
var application = require("application");
application.on(application.uncaughtErrorEvent, function (args) {
if (args.android) {
// For Android applications, args.android is an NativeScriptError.
console.log("NativeScriptError: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is NativeScriptError.
console.log("NativeScriptError: " + args.ios);
}
});
If I go by the above then I have the following questions. Would appreciate if somebody can confirm if this means every-time the app is crashing it will generate this application.uncaughtErrorEvent event? Can I rely on it?
If it is true then maybe I can make a REST call to my backend and store date, time and whatever is in args.android or args.ios.
If above is not the correct way then can somebody please help me on how to go about doing this?
Any help is highly appreciated. Thank you!
The application.onUncaughtError will be hit probably 95-98% of the time during a crash; it is pretty reliable. I have seen the app crash without any notice at all it just goes poof, but I'm not sure any reporting system can handle that one.
The way I do it is during the app startup I register a couple things:
I create a global.error function; this is used for anything (like try/catch, promise/catch) that needs to send the errors through to be logged remotely. So anywhere in my codebase I can do a global.error(theError); and it will be handled; this way I do NOT have to worry about trying to load or require things while an error is taking place, as that can cause other errors.
I use the onUncaughtError event to catch anything that is not normally caught, and then notify the user that an error has occurred and quit the app. (in this case, trying to recover is not recommended as you have no idea where the error was thrown from...)
If I use a worker thread, When I startup a worker I register the worker.onerror to forward its data to the main threads global.error function AND I have a specific message from the workers' version of the global.error that sends the error back to the primary thread. This way if the worker itself calls global.error that message is passed back to the main thread and then to the global.error on the main thread which handles everything properly.
This technique allows me to catch pretty much all errors that can occur. The main global.error function and the onUncaughtError both use a simple reporting library that I built that reports all the data back to one of my servers, IF the device is online. If the device is offline, it can optionally save the data to a reporting file to be uploaded later; or just ignore it.
It also has safety checks to verify the error isn't a network error (we don't want the error reporting to go into a loop, i.e. trying to report the error causes an error, which then tries to report the error; so in the event it is a certain type of network error; it will ignore those. )

How can I log javascript errors with Poltergeist/Capybara/Rspec?

I'm using Rspec/Capybara with Poltergeist as a driver to write tests for some large web applications.
My issue is that I would like to record the messages that appear on the console, but so far I've been unable to do so.
I am aware of the options js_errors and phantomjs_logger, but I have had some issues with them:
if I set js_errors: false, the file I specify in phantomjs_logger stays empty;
if I set js_errors: true, console.log messages are logged in the file specified in phantomjs_logger, but then almost all my specs fail because of
javascript errors that may not even be relevant to the navigation example I'm testing.
Any idea on how I can save the console messages while not breaking specs on every js error?
CLARIFICATION:
I have no control over the development, my task is to check the stability of the whole stack of the applications in the various environments, accessing from the front-end, so clearing out all the javascript errors is out of the question. The specs I'm writing are also supposed to ignore javascript errors if they don't impair the usage of the interface.
You can't. The PhantomJS client catches javascript error messages and adds them to an array. Then when a command completes, if js_errors == true, that array is checked and if not empty the javascript errors are returned and trigger an error in the test. There is no other API in poltergeist for accessing those errors. It sounds like you need to have a discussion with your manager about the wisdom of just ignoring JS errors if they apparently don't impair usage - it's a potentially dangerous development practice

Chromecast sample sender application CastHelloText-chrome ends with error when trying to get session

I have problem with launching Google-Cast application similar to sample CastHelloText-chrome. I slightly modified example code for my specific purposes. The goal for creating this application is to send and show image data directly in Chromecast device.
Particularly the difference between official sample and my code is in message format and its content, sent by sender application. Sender application took png image coded by base64 and send through message bus with custom namespace. Receiver application get this message and use this as data source for html object <img>.
Error appears when I do this steps:
Reload sender page, checking console if any device found.
Send the form by just pushing enter on input box (text is ignored).
Now a popup from Chromecast extension shows. Next there are two scenarios:
3a) I confirm casting to device by choosing one from the list, then I get this error message in console:
onError: {"code":"channel_error","description":"Error: Timeout","details":null}
3b) I just click somewhere else, I get this error:
onError: {"code":"cancel","description":"User closed popup menu","details":null}
Both of errors are caused by calling function chrome.cast.requestSession in chromehellotext.html at line 161, but what's really wrong I don't know.
When I step sender script I realize that function sessionListener is never called. I know that something go wrong when code try to call chrome.cast.requestSession, where described error raises. So I need help if I missed about right way to use Google-Cast API or If this problem has something to do with networking issues.
Receiver application is registered on Google Cast SDK Developer Console and I'm testing on registered device with some serial number. I'm using Google Chrome in version 42.0.2300.2 canary (64-bit) and Chrome version 40.0.2214.111 (current stable I suppose). For testing I also tried to turn off Windows Firewall entirely but with no luck.
Edit:
There were some syntactic errors that caused error message described above.
It seems like you are trying to use the data/control channel to send an image; please don't do that; that channel is not meant to be used for large data communications; in fact it cannot send anything which approaches or exceeds 64k. If your goal is to send images from your local machine, you would need to run a local web server on your local machine and serve images through the web server.
For and easiest tutorial you can have a look to this tutorial.
It is well explained in this tutorial.
Chromecast Sender application
There is no need to maintain session by yourself.
just add button and enjoy casting
mCastManager.addMediaRouterButton(mediaRoutebtn);
I found a source of my problem. There was something wrong in receiver code - syntactic and runtime errors, so I must admit that my code wasn't functional. Now its working in terms of launching application and getting session.
Unfortunate thing is that the error message generated by Chromecast extension didn't match the actual error - at least it was a bit confusing when I didn't know what's really happening on receiver side without ability to debug the code.

Calling DisplayRequest.RequestRelease function in windows 8 app

I want to turn off the display at a particular point using DisplayRequest.RequestRelease but im getting various exception. When i tried for desktop im getting "Arithmetic result exceeded 32 bits" error. In phone im getting system.excecutionEngine exception. I need to know the correct usage of this function.
There are two things wrong here.
DisplayRequest.RequestRelease is used to release a previous request to keep the display alive. If you haven't called RequestActive before, then it won't work and will throw the exception.
If you are doing it to release a previous call, then it's possible that things are going wrong after a suspend operation, because you may have inadvertently called RequestRelease in your OnNavigatingFrom member. Please see my blog for full details at Most of my Windows 8 Apps are broken. Yours probably are too

Handle Incoming call crash while App Start

I have run into an Interesting scenario. Its also present here by someone on msdn forums
When I launch my application, if I lock the screen or if a call comes at that time and on resume after unlocking or disconnecting the call in respective scenarios, the application crashes throwing 0x8000ffff error. This I have observed also happens when an emailcomposetask is open from my application.
Previously I thought that it was because I was not handling Obscured and Unobscured. But now that I am handling them, still I am receiving the same case. I have observed that many other applications also crash but there are some applications like Facebook and Twitter which are able to handle it. Has any one faced this same situation? Can you please provide me a fix for this?
Am I doing anything wrong?
also note that I have changed my default loading page. Its not mainPage.xaml but xyz.xaml, where I am checking for tokens and redirecting user to mainPage automatically without any button click.
Edit : Added StackTrace
at Microsoft.Phone.Execution.NativeEmInterop.NotifyFullObscurityChanged(Boolean isObscured)
at Microsoft.Phone.Shell.PhoneApplicationService.OnFullObscurityChanged(Object sender, LockStateChangeEventArgs e)
at Microsoft.Phone.Shell.Interop.ShellPageManager.ShellPageCallback_OnLockStateChange(Object source, LockStateChangeEventArgs e)
at Microsoft.Phone.Shell.Interop.ShellPageCallback.FireOnLockStateChange(Boolean fLocked)`
This mainly happens because of the code in OnNavigatedTo() and Page_Loaded() event handlers. Place break points and check for the issues in those two methods.
When an app is resumed in the cases you mentioned, these two methods are called in the same order.
Hope this solves your problem.
Update based on your comments:
There you are. You are clearing the entire Navigation history, and hence it dont know where to go now(even the current page is removed).
My suggestion is, Move your back history removal code from OnNavigated to the Page_Loaded event.

Resources