void SetUpContentPlayer() { var contentURL = new Foundation.NSUrl(contentUrlString); AVPlayer player = new AVPlayer(contentURL); aVPlayerViewController = new AVPlayerViewController(); aVPlayerViewController.Player = player; // Set up your content playhead and contentComplete callback. contentPlayhead = new IMAAVPlayerContentPlayhead(player); NSNotificationCenter.DefaultCenter.AddObserver(new NSString("AVPlayerItemDidPlayToEndTime"), ContentDidFinishPlaying); //NSNotificationCenter.DefaultCenter.AddObserver(this // , new ObjCRuntime.Selector("ViewController.contentDidFinishPlaying(_:)") // , new NSString("AVPlayerItemDidPlayToEndTime") // , player.CurrentItem) ; // contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: player) //NotificationCenter.default.addObserver( // self, // selector: #selector(ViewController.contentDidFinishPlaying(_:)), // name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, // object: player.currentItem); ShowContentPlayer(); }
public void OpenURI(string selectedText) { NSString searchText = new NSString(selectedText); searchText = searchText.CreateStringByAddingPercentEscapes(NSStringEncoding.UTF8); Foundation.NSUrl url = new Foundation.NSUrl($"https://www.google.com/search?q={searchText}"); UIApplication.SharedApplication.OpenUrl(url); }
private void CallNumber(object sender, EventArgs e) { var button = sender as UIButton; var phoneNumber = button.Title(UIControlState.Normal); var url = new Foundation.NSUrl("tel:" + phoneNumber); var alert = UIAlertController.Create("Alert", "Simulated call to " + phoneNumber, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null); }
protected override void OnRedirectPageLoaded(Uri url, IDictionary <string, string> query, IDictionary <string, string> fragment) { System.Diagnostics.Debug.WriteLine(String.Format("OnRedirectPageLoaded: {0}", url)); if (fragment.ContainsKey("access_token")) { var cookieUrl = new Foundation.NSUrl(url.AbsoluteUri); var cookies = NSHttpCookieStorage.SharedStorage.CookiesForUrl(cookieUrl); foreach (NSHttpCookie c in cookies) { WebAPI.CookieContainer.Add(WebAPI.BaseURI, new Cookie(c.Name, c.Value)); } var account = new Account("", fragment); OnSucceeded(account); } }
protected override void OnRedirectPageLoaded(Uri url, IDictionary<string, string> query, IDictionary<string, string> fragment) { System.Diagnostics.Debug.WriteLine(String.Format("OnRedirectPageLoaded: {0}", url)); if (fragment.ContainsKey("access_token")) { var cookieUrl = new Foundation.NSUrl(url.AbsoluteUri); var cookies = NSHttpCookieStorage.SharedStorage.CookiesForUrl(cookieUrl); foreach (NSHttpCookie c in cookies) { WebAPI.CookieContainer.Add(WebAPI.BaseURI, new Cookie(c.Name, c.Value)); } var account = new Account("", fragment); OnSucceeded(account); } }
void GetAssetFromUrl(Foundation.NSUrl url) { try { var inputPath = url; var outputPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/output.mp3"; var outputURL = new NSUrl(outputPath); NSData data = NSData.FromUrl(outputURL); //compress the video file var asset = new AVUrlAsset(inputPath, (AVUrlAssetOptions)null); var exportSession = AVAssetExportSession.FromAsset(asset, "AVAssetExportPresetLowQuality"); exportSession.OutputUrl = outputURL; exportSession.OutputFileType = AVFileType.CoreAudioFormat; exportSession.ExportAsynchronously(() => { Console.WriteLine(exportSession.Status); //prints status "Failed".... exportSession.Dispose(); }); //var asset = new ALAssetsLibrary(); //UIImage image; //asset.AssetForUrl( // url, // (ALAsset obj) => // { // var assetRep = obj.DefaultRepresentation; // var filename = assetRep.Filename; // }, // (NSError err) => // { // Console.WriteLine(err); // } // ); } catch (Exception ex) { } }
public override void FinishedRecording(AVCaptureFileOutput captureOutput, Foundation.NSUrl outputFileUrl, Foundation.NSObject[] connections, Foundation.NSError error) { NSUrl urlCompressed = new NSUrl(System.IO.Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mov"), false); compressVideo(outputFileUrl, urlCompressed); /* * NSData data = NSData.FromUrl(outputFileUrl); * byte[] dataBytes = new byte[data.Length]; * System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length)); * UIApplication.SharedApplication.InvokeOnMainThread(delegate * { * (Element as CustomVideoCamera).SetPhotoResult(outputFileUrl.ToString(), dataBytes, 0, 0); * activityIndicator.StopAnimating (); * }); */ //You can use captureOutput and outputFileUrl here.. //throw new NotImplementedException(); }
public override void ViewDidLoad() { base.ViewDidLoad(); translateButton.TouchUpInside += delegate { var translator = new PhoneTranslator(); _translatedNumber = translator.ToNumber(phoneNumberText.Text); if (string.IsNullOrEmpty(_translatedNumber)) { // No hay número a llamar callButton.SetTitle("Llamar", UIControlState.Normal); callButton.Enabled = false; } else { // Hay un posible número telefónico a llamar callButton.SetTitle($"Llamar a {_translatedNumber}", UIControlState.Normal); callButton.Enabled = true; } }; callButton.TouchUpInside += delegate { _phoneNumbers.Add(_translatedNumber); var url = new Foundation.NSUrl($"tel:{_translatedNumber}"); // Utilizar el manejador de URL con el prefijo tel: para invocar a la // aplicación Phone de Apple, de lo contrario mostrar un diálogo de alerta. if (!UIApplication.SharedApplication.OpenUrl(url)) { var alert = UIAlertController.Create("No soportado", "El esquema 'tel:' no es soportado en este dispositivo", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } }; // Perform any additional setup after loading the view, typically from a nib. }
//Check if CRCloudMetaData is an image public Boolean IsImage(CRCloudMetaData metaData) { try { string fileExtention = new Foundation.NSUrl(metaData.Name).PathExtension.ToLower(); if (fileExtention == "jpg" || fileExtention == "jpeg" || fileExtention == "png") { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
//Check if CRCloudMetaData is a video public Boolean IsVideo(CRCloudMetaData metaData) { try { string fileExtention = new Foundation.NSUrl(metaData.Name).PathExtension.ToLower(); if (fileExtention == "mov" || fileExtention == "mp4" || fileExtention == "mkv" || fileExtention == "avi" || fileExtention == "wmv") { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
public void WillPerformClientRedirect(WebKit.WebView sender, Foundation.NSUrl toUrl, double secondsDelay, Foundation.NSDate fireDate, WebKit.WebFrame forFrame) { var url = sender.MainFrameUrl; if (!Authenticator.HasCompleted) { Uri uri; if (Uri.TryCreate(url, UriKind.Absolute, out uri)) { if (Authenticator.CheckUrl(uri, GetCookies(url))) { forFrame.StopLoading(); return; } } } else { forFrame.StopLoading(); } }
public bool Save(NSUrl url, bool auxiliaryFile, out NSError error) { return(Save(url, auxiliaryFile ? NSDataWritingOptions.Atomic : (NSDataWritingOptions)0, out error)); }
public bool RecordAudio() { try { var audioSession = AVFoundation.AVAudioSession.SharedInstance (); var err = audioSession.SetCategory (AVFoundation.AVAudioSessionCategory.PlayAndRecord); if (err != null) { return false; } err = audioSession.SetActive (true); if (err != null) { return false; } string directoryname = string.Empty; try { var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); directoryname = System.IO.Path.Combine (documents, "PurposeColor/Audio"); System.IO.Directory.CreateDirectory(directoryname); } catch (Exception ex) { var test = ex.Message; } fileName = string.Format ("Audio{0}.wav", DateTime.Now.ToString ("yyyyMMddHHmmss")); audioFilePath = System.IO.Path.Combine (directoryname, fileName); url = Foundation.NSUrl.FromFilename (audioFilePath); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary Foundation.NSObject[] values = new NSObject[] { NSNumber.FromFloat (44100.0f), //Sample Rate NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat NSNumber.FromInt32 (1), //Channels NSNumber.FromInt32 (16) //PCMBitDepth }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys (values, keys); var error = new NSError(); //Set recorder parameters recorder = AVAudioRecorder.Create (url, new AudioSettings (settings), out error); //Set Recorder to Prepare To Record recorder.PrepareToRecord (); recorder.Record (); return true; } catch (Exception ex) { var tt = ex.Message; return false; } }
public void Appel(string numero) { var url = new Foundation.NSUrl("tel:" + numero); UIApplication.SharedApplication.OpenUrl(url); }
private Task <FileData> TakeMediaAsync() { var id = GetRequestId(); var ntcs = new TaskCompletionSource <FileData>(id); if (Interlocked.CompareExchange(ref _completionSource, ntcs, null) != null) { throw new InvalidOperationException("Only one operation can be active at a time"); } var allowedUtis = new string[] { UTType.UTF8PlainText, UTType.PlainText, UTType.RTF, UTType.PNG, UTType.Text, UTType.PDF, UTType.Image, UTType.UTF16PlainText, UTType.FileURL }; var importMenu = new UIDocumentMenuViewController(allowedUtis, UIDocumentPickerMode.Import) { Delegate = this, ModalPresentationStyle = UIModalPresentationStyle.Popover }; UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(importMenu, true, null); var presPopover = importMenu.PopoverPresentationController; if (presPopover != null) { presPopover.SourceView = UIApplication.SharedApplication.KeyWindow.RootViewController.View; presPopover.PermittedArrowDirections = UIPopoverArrowDirection.Down; } Handler = null; Handler = (s, e) => { var tcs = Interlocked.Exchange(ref _completionSource, null); FileData fileData = null; switch (_kind) { case OldOrNew.Old: fileData = new FileData(e.FilePath, e.FileName, () => File.OpenRead(e.FilePath)); break; case OldOrNew.New: fileData = new FileData(e.FilePath, e.FileName, () => { var url = new Foundation.NSUrl(e.FilePath); return(new FileStream(url.Path, FileMode.Open, FileAccess.Read)); }); break; } tcs?.SetResult(fileData); }; return(_completionSource.Task); }
public NSDictionary(NSUrl url) : base(url) { }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // var TranslatedNumber = string.Empty; TranslateButton.TouchUpInside += (object sender, EventArgs e) => { var Translator = new PhoneTranslator(); TranslatedNumber = Translator.ToNumber(PhoneNumberText.Text); if (string.IsNullOrWhiteSpace(TranslatedNumber)) { // No hay número a llamar CallButton.SetTitle("Llamar", UIControlState.Normal); CallButton.Enabled = false; } else { // Hay un posible número telefónico a llamar CallButton.SetTitle($"Llamar al {TranslatedNumber}", UIControlState.Normal); CallButton.Enabled = true; } }; CallButton.TouchUpInside += (object sender, EventArgs e) => { PhoneNumbers.Add(TranslatedNumber); var URL = new Foundation.NSUrl($"tel:{TranslatedNumber}"); // Utilizar el manejador de URL con el prefijo tel: para invocar a la // aplicacionPhone de Apple, de lo contrario mostrar un dialogo de alerta if (!UIApplication.SharedApplication.OpenUrl(URL)) { var Alert = UIAlertController.Create("No soportado", "El esquema 'tel:' no es soportado en este dispositivo", UIAlertControllerStyle.Alert); Alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(Alert, true, null); } }; btnValidateView.TouchUpInside += (object sender, EventArgs e) => { // Puede instaciarse el controlador con ID "CallHistoryController // establecido en el diseño if (Storyboard.InstantiateViewController("ValidateViewController") is ValidateViewController Controller) { // Coloca al Controlador en la pila de navegación NavigationController.PushViewController(Controller, true); } }; CallHistoryButton.TouchUpInside += (object sender, EventArgs e) => { // Puede instaciarse el controlador con ID "CallHistoryController // establecido en el diseño if (Storyboard.InstantiateViewController("CallHistoryController") is CallHistoryController Controller) { // Proporciona la lista de número telefónicos a CallHistoryController Controller.PhoneNumbers = PhoneNumbers; // Coloca al Controlador en la pila de navegación NavigationController.PushViewController(Controller, true); } }; }
private Task <FileData> TakeMediaAsync() { var id = GetRequestId(); var ntcs = new TaskCompletionSource <FileData> (id); if (Interlocked.CompareExchange(ref _completionSource, ntcs, null) != null) { throw new InvalidOperationException("Only one operation can be active at a time"); } var allowedUtis = new string [] { UTType.UTF8PlainText, UTType.PlainText, UTType.RTF, UTType.PNG, UTType.Text, UTType.PDF, UTType.Image, UTType.UTF16PlainText, UTType.FileURL }; var importMenu = new UIDocumentMenuViewController(allowedUtis, UIDocumentPickerMode.Import) { Delegate = this, ModalPresentationStyle = UIModalPresentationStyle.Popover }; UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(importMenu, true, null); var presPopover = importMenu.PopoverPresentationController; if (presPopover != null) { presPopover.SourceView = UIApplication.SharedApplication.KeyWindow.RootViewController.View; presPopover.PermittedArrowDirections = UIPopoverArrowDirection.Down; } Handler = null; Handler = (s, e) => { var tcs = Interlocked.Exchange(ref _completionSource, null); tcs?.SetResult(new FileData(e.FilePath, e.FileName, () => { // Handles were the iCloud give back filePath with file:/private/var .ect if (e.FilePath.StartsWith("file:")) { var url = new Foundation.NSUrl(e.FilePath); return(new FileStream(url.Path, FileMode.Open, FileAccess.Read)); } // If it's not an iCloud item (Not sure this will ever be the case) then treat it normaly else { return(File.OpenRead(e.FilePath)); } })); }; return(_completionSource.Task); }