use of cli.MonoTouch.Foundation.NSUrl in project playn by threerings.
the class IOSAssets method getRemoteImage.
@Override
public Image getRemoteImage(String url, float width, float height) {
final IOSAsyncImage image = new IOSAsyncImage(platform.graphics().ctx, width, height);
new NSUrlConnection(new NSUrlRequest(new NSUrl(url)), new NSUrlConnectionDelegate() {
private NSMutableData data = new NSMutableData();
@Override
public void ReceivedData(NSUrlConnection conn, NSData data) {
this.data.AppendData(data);
}
@Override
public void FailedWithError(NSUrlConnection conn, NSError error) {
onFailure(new Exception(error.get_LocalizedDescription()));
}
@Override
public void FinishedLoading(NSUrlConnection conn) {
try {
setImageLater(image, UIImage.LoadFromData(this.data), Scale.ONE);
} catch (Throwable cause) {
onFailure(cause);
}
}
protected void onFailure(final Throwable cause) {
setErrorLater(image, cause);
}
}, true);
return image;
}
use of cli.MonoTouch.Foundation.NSUrl in project playn by threerings.
the class IOSAudio method createAVAP.
Sound createAVAP(NSUrl url) {
final IOSSoundAVAP sound = new IOSSoundAVAP();
ThreadPool.QueueUserWorkItem(new WaitCallback(new WaitCallback.Method() {
public void Invoke(Object arg) {
NSUrl url = (NSUrl) arg;
NSError[] error = new NSError[1];
AVAudioPlayer player = AVAudioPlayer.FromUrl(url, error);
if (error[0] == null) {
dispatchLoaded(sound, player);
} else {
platform.log().warn("Error loading sound [" + url + ", " + error[0] + "]");
dispatchLoadError(sound, new Exception(error[0].ToString()));
}
}
}), url);
return sound;
}
use of cli.MonoTouch.Foundation.NSUrl in project playn by threerings.
the class IOSNet method execute.
@Override
protected void execute(BuilderImpl req, Callback<Response> callback) {
NSMutableUrlRequest mreq = new NSMutableUrlRequest(new NSUrl(req.url));
for (Header header : req.headers) {
mreq.set_Item(header.name, header.value);
}
mreq.set_HttpMethod(req.method());
if (req.isPost()) {
mreq.set_Item("Content-type", req.contentType());
if (req.payloadString != null) {
mreq.set_Body(NSData.FromString(req.payloadString, NSStringEncoding.wrap(NSStringEncoding.UTF8)));
} else {
mreq.set_Body(NSData.FromArray(req.payloadBytes));
}
}
sendRequest(mreq, callback);
}
Aggregations