Esempio n. 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            //largely taken from the xamarin website videoplayer tutorial

            //build the path to the location where the movie was saved
            var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
            var library = System.IO.Path.Combine (documents, "..", "Library");
            var urlpath = System.IO.Path.Combine (library, "sweetMovieFilm.mov");

            NSUrl url = new NSUrl (urlpath, false);

            _asset = AVAsset.FromUrl(url);
            _playerItem = new AVPlayerItem (_asset);
            _player = new AVPlayer (_playerItem);

            _playerLayer = AVPlayerLayer.FromPlayer (_player);
            _playerLayer.Frame = View.Frame;
            View.Layer.AddSublayer (_playerLayer);

            //this code makes UI controls sit on top of the movie layer.  Allows you to just place the controls in interface builder
            UIView cameraView = new UIView ();
            this.View.AddSubview (cameraView);
            this.View.SendSubviewToBack (cameraView);
            cameraView.Layer.AddSublayer (_playerLayer);

            _player.Play ();

            this.btnDonePlaying.TouchUpInside += stopPlaying;
        }
Esempio n. 2
0
        public MyPlayerView(bool noController, RectangleF frame)
        {
            this.Frame = frame;
            if (noController) {
                var asset = AVAsset.FromUrl (NSUrl.FromFilename ("sample.m4v"));
                var playerItem = new AVPlayerItem (asset);
                this._MyAvPlayer = new AVPlayer (playerItem);

                var playerLayer = AVPlayerLayer.FromPlayer (this._MyAvPlayer);
                playerLayer.Frame = this.Frame;
                _MyAvPlayer.Play ();

                this.Layer.AddSublayer (playerLayer);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            _asset = AVAsset.FromUrl (NSUrl.FromFilename ("sample.m4v"));
            _playerItem = new AVPlayerItem (_asset);

            _player = new AVPlayer (_playerItem);
            _playerLayer = AVPlayerLayer.FromPlayer (_player);
            _playerLayer.Frame = View.Frame;

            View.Layer.AddSublayer (_playerLayer);

            _player.Play ();
        }
		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			if (Player == null) {
				seekToZeroBeforePlaying = false;
				Player = new AVPlayer ();
				Player.AddObserver (this, (NSString)"rate", NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New, RateObservationContext.Handle);

				playerView.player = Player;
			}

			addTimeObserverToPlayer ();

			// Build AVComposition and AVVideoComposition objects for playback
			Editor.BuildCompositionObjects (true);
			synchronizePlayerWithEditor ();

		}
Esempio n. 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
			
            
            if (((MissionViewModel)ViewModel).Mission.LiveStream)
            {
                chatView.Hidden = false;
                messageField.Hidden = false;
                sendButton.Hidden = false;
                
                firstTitle.Hidden = true;
                secondTitle.Hidden = true;
                imageView.Hidden = true;
                
                var streamingUri = ((MissionViewModel)ViewModel).LiveStreamViewModel.LiveStreamUrl;
                
                _asset = AVAsset.FromUrl(NSUrl.FromString(streamingUri));
                _playerItem = new AVPlayerItem(_asset);
                
                _player = new AVPlayer(_playerItem);

                _playerLayer = AVPlayerLayer.FromPlayer(_player);
                _playerLayer.Frame = new RectangleF(21, 88, 602, 311);
                View.Layer.AddSublayer(_playerLayer);
                _player.Play();
                
                ((MissionViewModel)ViewModel).LiveStreamViewModel.UserName = "******";
                
                chatView.Text = "";
                
                var previousText = string.Empty;
                
                SunnySocket.MessageReceivedAsyncCallback = (string name, string message) =>
                InvokeOnMainThread(() =>
                {
                    if (message != previousText)
                    {
                        chatView.Text = name + " - " + message + "\n" + chatView.Text;
                        chatView.Font = UIFont.FromName("HelveticaNeue-Bold", 15);
                        chatView.TextColor = UIColor.FromRGBA(0.027f, 0.102f, 0.389f, 1.000f);
                        previousText = message;
                    }
                });
                
                messageField.ShouldReturn += (x) =>
                {
                    ((MissionViewModel)ViewModel).LiveStreamViewModel.SendMessageCommand.Execute(null); 
                    return true;
                };
                    
                var set = this.CreateBindingSet<MissionView, MissionViewModel>();
                set.Bind(title).To(vm => vm.Mission.Name);
                set.Bind(messageField).To(vm => vm.LiveStreamViewModel.Message);
                set.Bind(backButton).To("GoBackCommand"); 
                set.Bind(sendButton).To("LiveStreamViewModel.SendMessageCommand"); 
                set.Apply();
                
                messageField.BecomeFirstResponder();
            }
            else
            {
                chatView.Hidden = true;
                messageField.Hidden = true;
                sendButton.Hidden = true;
                
                var imageBorder = new UIButton(UIButtonType.System);
                imageBorder.Frame = new RectangleF(imageView.Frame.X - 1, imageView.Frame.Y - 1, imageView.Frame.Width + 2, imageView.Frame.Height + 2);
                imageBorder.BackgroundColor = UIColor.Clear;
                imageBorder.Layer.BorderColor = UIColor.FromRGBA(0.631f, 0.816f, 0.922f, 1.000f).CGColor;
                imageBorder.Layer.CornerRadius = 4;
                imageBorder.Layer.BorderWidth = 1;
                View.AddSubview(imageBorder);
            
                var webview = new UIWebView();
                webview.Frame = new RectangleF(450, 87, 554, 681);
            
                var webviewBorder = new UIButton(UIButtonType.System);
                webviewBorder.Frame = new RectangleF(webview.Frame.X - 1, webview.Frame.Y - 1, webview.Frame.Width + 2, webview.Frame.Height + 2);
                webviewBorder.BackgroundColor = UIColor.Clear;
                webviewBorder.Layer.BorderColor = UIColor.FromRGBA(0.631f, 0.816f, 0.922f, 1.000f).CGColor;
                webviewBorder.Layer.CornerRadius = 4;
                webviewBorder.Layer.BorderWidth = 1;
                View.AddSubview(webviewBorder);
            
                View.AddSubview(webview);
            
                var newsButton = new UIButton(UIButtonType.System);
                newsButton.Frame = new RectangleF(21, 485, 360, 60);
                newsButton.BackgroundColor = UIColor.Clear;
                newsButton.Layer.BorderColor = UIColor.FromRGBA(0.631f, 0.816f, 0.922f, 1.000f).CGColor;
                newsButton.Layer.CornerRadius = 4;
                newsButton.Layer.BorderWidth = 1;
                View.AddSubview(newsButton);

       
                var notifyButton = new UIButton(UIButtonType.System);
                notifyButton.Frame = new RectangleF(21, 605, 360, 60);
                notifyButton.BackgroundColor = UIColor.Clear;
                notifyButton.Layer.BorderColor = UIColor.FromRGBA(0.631f, 0.816f, 0.922f, 1.000f).CGColor;
                notifyButton.Layer.CornerRadius = 4;
                notifyButton.Layer.BorderWidth = 1;
                View.AddSubview(notifyButton);

                notifyButton.TouchUpInside += (sender, e) =>
                {
                    notifyButton.Enabled = false;
                    new UIAlertView("Thank you", "You'll receive a notification when we go fly fly (or boom boom)", null, "Ok").Show();
                };
            
                var imageViewLoader = new MvxImageViewLoader(() => this.imageView);
                        
                var set = this.CreateBindingSet<MissionView, MissionViewModel>();
                set.Bind(imageViewLoader).To(vm => vm.Mission.ImageUri);
                set.Bind(title).To(vm => vm.Mission.Name);
                set.Bind(newsButton).To("ShowMissionNewsOverviewCommand");
                set.Bind(notifyButton).To("InitPushCommand"); 
                set.Bind(backButton).To("GoBackCommand"); 
                set.Apply();
            
                var html = ((MissionViewModel)ViewModel).Mission.Text;
                webview.LoadHtmlString(html, null);     
            
                webview.ShouldStartLoad += shouldStartLoad; 
            }
                   
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.RecordingStatusLabel.Text = "";
            this.LengthOfRecordingLabel.Text = "";

            // start recording wireup
            this.StartRecordingButton.TouchUpInside += (sender, e) =>
            {
                Console.WriteLine("Begin Recording");

                var session = AVAudioSession.SharedInstance();

                NSError error = null;
                session.SetCategory(AVAudioSession.CategoryRecord, out error);
                if (error != null)
                {
                    Console.WriteLine(error);
                    return;
                }

                session.SetActive(true, out error);
                if (error != null)
                {
                    Console.WriteLine(error);
                    return;
                }

                if (!PrepareAudioRecording())
                {
                    RecordingStatusLabel.Text = "Error preparing";
                    return;
                }

                if (!recorder.Record())
                {
                    RecordingStatusLabel.Text = "Error preparing";
                    return;
                }

                this.stopwatch = new Stopwatch();
                this.stopwatch.Start();
                this.LengthOfRecordingLabel.Text = "";
                this.RecordingStatusLabel.Text = "Recording";
                this.StartRecordingButton.Enabled = false;
                this.StopRecordingButton.Enabled = true;
                this.PlayRecordedSoundButton.Enabled = false;
            };

            // stop recording wireup
            this.StopRecordingButton.TouchUpInside += (sender, e) =>
            {
                this.recorder.Stop();

                this.LengthOfRecordingLabel.Text = string.Format("{0:hh\\:mm\\:ss}", this.stopwatch.Elapsed);
                this.stopwatch.Stop();
                this.RecordingStatusLabel.Text = "";
                this.StartRecordingButton.Enabled = true;
                this.StopRecordingButton.Enabled = false;
                this.PlayRecordedSoundButton.Enabled = true;
            };

            observer = NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.DidPlayToEndTimeNotification, delegate (NSNotification n)
            {
                player.Dispose();
                player = null;
            });

            // play recorded sound wireup
            this.PlayRecordedSoundButton.TouchUpInside += (sender, e) =>
            {
                try
                {
                    Console.WriteLine("Playing Back Recording " + this.audioFilePath.ToString());

                    // The following line prevents the audio from stopping
                    // when the device autolocks. will also make sure that it plays, even
                    // if the device is in mute
                    NSError error = null;
                    AVAudioSession.SharedInstance().SetCategory(AVAudioSession.CategoryPlayback, out error);
                    if (error != null)
                    {
                        throw new Exception(error.DebugDescription);
                    }
                    //AudioSession.Category = AudioSessionCategory.MediaPlayback;

                    this.player = new AVPlayer(this.audioFilePath);
                    this.player.Play();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("There was a problem playing back audio: ");
                    Console.WriteLine(ex.Message);
                }
            };
        }
Esempio n. 7
0
        public FT_MessageViewController(UIImage mapImage,CLLocationCoordinate2D location)
            : base(UITableViewStyle.Grouped, null)
        {
            imageList = new List<string> ();
            audioList = new List<NSUrl> ();

            _mapScreenShot = mapImage;
            this.Pushing = true;

            var _shareBtn = new UIBarButtonItem (){
                Title = "Send"
            };
            _shareBtn.Clicked += (object sender, EventArgs e) => {

                if (MFMailComposeViewController.CanSendMail){
                    var mailController = new MFMailComposeViewController ();
                    saveMessage(location);
                    var msg = string.Format("Location Coordinates : http://maps.google.com/maps?z=12&t=m&q=loc:{0}+{1}",location.Latitude,location.Longitude);
                    mailController.SetMessageBody(msg,false);

                    for(int i=0 ; i<audioList.Count; i++){

                        var path = audioList[i].AbsoluteString;
                        NSFileManager.SetSkipBackupAttribute(path,true);
                        NSData aData = NSData.FromUrl(audioList[i]);
                        mailController.AddAttachmentData(aData,"audio/aac","Audio_"+i);
                    }

                    for(int i=0; i<imageList.Count; i++){
                        NSFileManager.SetSkipBackupAttribute(imageList[i],true);
                        NSData iData = NSData.FromUrl(new NSUrl(imageList[i],false) );
                        mailController.AddAttachmentData(iData,"image/jpg","Image_"+i);
                    }

                    mailController.Finished += (object s, MFComposeResultEventArgs ea) => {
                        ea.Controller.DismissViewController(true,null);
                    };
                    this.NavigationController.PresentViewController(mailController,true,null);

                    this.NavigationController.PopToRootViewController(true);
                }else{
                    new UIAlertView ("Error","No Email Account on the Device.",null,"OK",null).Show();
                }

            };
            this.NavigationItem.RightBarButtonItem = _shareBtn;

            Root = new RootElement ("Add");
            var mapS = new Section (){
                HeaderView = new UIImageView (CropImage (_mapScreenShot, 0, 150, 320, 240)),
            };
            var locationS = new Section ("Location Information"){
                new StringElement ("Latitude", location.Latitude.ToString ()),
                new StringElement ("Longitude",location.Longitude.ToString()),
            };

            var pictureS = new Section ("Picture");
            createTakePhotoBtn(pictureS);

            var recordingS = new Section ("Recording");
            createTakeRecordingBtn (recordingS);

            Root.Add (mapS);
            Root.Add (locationS);
            Root.Add (pictureS);
            Root.Add (recordingS);

            observer = NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.DidPlayToEndTimeNotification, delegate (NSNotification n) {
                //player.Dispose();
                player = null;
            });

            createDocumentFolder ();

            this.NavigationItem.HidesBackButton = true;
            var cancelBtn = new UIBarButtonItem ();
            cancelBtn.Title = "Cancel";
            cancelBtn.TintColor = UIColor.Red;
            this.NavigationItem.LeftBarButtonItem = cancelBtn;
            cancelBtn.Clicked += (object sender, EventArgs e) => {
                deleteDocumentFolder();
                this.NavigationController.PopToRootViewController(true);

            };
        }
Esempio n. 8
0
        private void playRecordVoice(NSUrl path)
        {
            try
            {
                Console.WriteLine("Playing Back Recording " + this.recordingUrl.ToString());

                // The following line prevents the audio from stopping
                // when the device autolocks. will also make sure that it plays, even
                // if the device is in mute
                NSError error = null;
                AVAudioSession.SharedInstance().SetCategory(AVAudioSession.CategoryPlayback, out error);
                if(error != null)
                {
                    throw new Exception(error.DebugDescription);
                }
                //AudioSession.Category = AudioSessionCategory.MediaPlayback;

                this.player = new AVPlayer(path);
                this.player.Play();
            }
            catch(Exception ex)
            {
                Console.WriteLine("There was a problem playing back audio: ");
                Console.WriteLine(ex.Message);
            }
        }
    public async override void ViewDidAppear(bool animated)
    {
      base.ViewDidAppear(animated);

      var url = new NSUrl(CurrentPodcastEpisode.AudioUrl);
      player = AVPlayer.FromUrl(url);

      var updated = await CurrentPodcastEpisode.GetTimeAsync();
      if (updated == null || updated.ShowNumber != CurrentPodcastEpisode.ShowNumber)
        return;

      if (player == null || player.Status != AVPlayerStatus.ReadyToPlay)
      {
        startTime = updated.CurrentTime;
        return;
      }

      await player.SeekAsync(CMTime.FromSeconds(updated.CurrentTime, 1));
      timer_Elapsed(null, null);//update UI
    }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            string path = NSBundle.MainBundle.PathForResource ("Dramatic2", "m4a");
            if (path != null) {
                memeEffect = AVPlayer.FromUrl (NSUrl.FromFilename (path));
                memeEffect.AddObserver (this, (NSString) "rate", (NSKeyValueObservingOptions)0, MemePlaybackContext);
            }
            path = NSBundle.MainBundle.PathForResource ("Sosumi", "wav");
            if (path != null)
                beepEffect = AVPlayer.FromUrl (NSUrl.FromFilename (path));

            setupAVCapture ();

            if (MaxZoom == 1f && device != null) {
                displayErrorOnMainQueue (null, "Device does not support zoom");
                slider.Enabled = false;
            }
        }
Esempio n. 11
0
		private void initializeVideo()
		{
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
			var library = System.IO.Path.Combine (documents, "..", "Library");
			var urlpath = System.IO.Path.Combine (library, "sweetMovieFilm.mov");

			url = new NSUrl (urlpath, false);

			_asset = AVAsset.FromUrl(url);
			_playerItem = new AVPlayerItem (_asset);


			_player = new AVPlayer (_playerItem);

			_notificationHandle = NSNotificationCenter.DefaultCenter.AddObserver (AVPlayerItem.DidPlayToEndTimeNotification, VideoDonePlaying);


			_playerLayer = AVPlayerLayer.FromPlayer (_player);
			_playerLayer.Frame = View.Frame;

		}
		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			if (Player == null) {
				seekToZeroBeforePlaying = false;
				Player = new AVPlayer ();
				playerView.Player = Player;
				compositionDebugView.Player = Player;
			}

			AddTimeObserverToPlayer ();

			Editor.BuildCompositionObjects (true);
			SynchronizeWithEditor ();

			// Set our AVPlayer and all composition objects on the AVCompositionDebugView
			compositionDebugView.Player = Player;
			compositionDebugView.SynchronizeToCompositoin (Editor.Composition, Editor.VideoComposition, Editor.AudioMix);
			compositionDebugView.SetNeedsDisplay ();
		}