Search in sources :

Example 1 with NSUrl

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;
}
Also used : NSData(cli.MonoTouch.Foundation.NSData) NSUrl(cli.MonoTouch.Foundation.NSUrl) NSUrlConnection(cli.MonoTouch.Foundation.NSUrlConnection) NSError(cli.MonoTouch.Foundation.NSError) NSUrlConnectionDelegate(cli.MonoTouch.Foundation.NSUrlConnectionDelegate) NSMutableData(cli.MonoTouch.Foundation.NSMutableData) NSUrlRequest(cli.MonoTouch.Foundation.NSUrlRequest) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with NSUrl

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;
}
Also used : AVAudioPlayer(cli.MonoTouch.AVFoundation.AVAudioPlayer) WaitCallback(cli.System.Threading.WaitCallback) NSUrl(cli.MonoTouch.Foundation.NSUrl) NSError(cli.MonoTouch.Foundation.NSError)

Example 3 with NSUrl

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);
}
Also used : NSMutableUrlRequest(cli.MonoTouch.Foundation.NSMutableUrlRequest) NSUrl(cli.MonoTouch.Foundation.NSUrl)

Aggregations

NSUrl (cli.MonoTouch.Foundation.NSUrl)3 NSError (cli.MonoTouch.Foundation.NSError)2 AVAudioPlayer (cli.MonoTouch.AVFoundation.AVAudioPlayer)1 NSData (cli.MonoTouch.Foundation.NSData)1 NSMutableData (cli.MonoTouch.Foundation.NSMutableData)1 NSMutableUrlRequest (cli.MonoTouch.Foundation.NSMutableUrlRequest)1 NSUrlConnection (cli.MonoTouch.Foundation.NSUrlConnection)1 NSUrlConnectionDelegate (cli.MonoTouch.Foundation.NSUrlConnectionDelegate)1 NSUrlRequest (cli.MonoTouch.Foundation.NSUrlRequest)1 WaitCallback (cli.System.Threading.WaitCallback)1 FileNotFoundException (java.io.FileNotFoundException)1