Example #1
0
        public MemoryStream GenerateThumbImage(string url, long usecond)
        {
            var asset          = AVAsset.FromUrl(NSUrl.FromFilename(url));
            var imageGenerator = AVAssetImageGenerator.FromAsset(asset);

            imageGenerator.AppliesPreferredTrackTransform = true;
            var actualTime = asset.Duration;

            CoreMedia.CMTime cmTime = new CoreMedia.CMTime(usecond, 2000000);
            NSError          error;
            var cgImage = imageGenerator.CopyCGImageAtTime(cmTime, out actualTime, out error);

            //AVAssetImageGenerator imageGenerator = new AVAssetImageGenerator(AVAsset.FromUrl((new Foundation.NSUrl(url))));
            //imageGenerator.AppliesPreferredTrackTransform = true;
            //var actualTime = asset.Duration;
            //CoreMedia.CMTime cmTime = new CoreMedia.CMTime(usecond, 1000000);
            //NSError error;
            //var cgImage = imageGenerator.CopyCGImageAtTime(cmTime, out actualTime, out error);
            //CMTime actualTime;
            //NSError error;
            //CGImage cgImage = imageGenerator.CopyCGImageAtTime(new CMTime(usecond, 1000000), out actualTime, out error);

            var zz = new UIImage(cgImage).AsJPEG().AsStream();
            var a  = new MemoryStream();

            zz.CopyTo(a);

            return(a);
            //return ImageSource.FromStream(() => new UIImage(cgImage).AsJPEG().AsStream()); //mageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream());
        }
Example #2
0
        public void file(string Title, byte[] _byet)
        {
            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string localFilename = "play.mov";  //same if I save the file as .mp4
            string localPath     = Path.Combine(documentsPath, localFilename);

            File.WriteAllBytes(localPath, _byet);



            _videobyte = _byet;

            this.Title = namefile = Title;

            local = localPath;

            avasset = AVAsset.FromUrl(NSUrl.FromFilename(localPath));
            var avplayerItem = new AVPlayerItem(avasset);
            var avplayer     = new AVPlayer(avplayerItem);

            avplayer.Play();
            this.Player = avplayer;
            // this.ShowsPlaybackControls = true;

            CoreMedia.CMTime m           = avplayer.CurrentTime;
            CMTime           duration    = avplayerItem.Duration;    //total time
            CMTime           currentTime = avplayerItem.CurrentTime; //playing time

            // this.Title =   avasset.Tracks..ToString();


            avplayer.Play();
        }
Example #3
0
        private void initControls()
        {
            UIImage image = new UIImage("close_white.png");
            var     frame = new CGRect(View.Frame.Width - 40, View.Frame.Height - 40, 30, 30);

            CloseButton       = new UIButton(UIButtonType.RoundedRect);
            CloseButton.Frame = frame;
            CloseButton.SetImage(image, UIControlState.Normal);



            CloseButton.TouchUpInside += delegate {
                _player.Rate = 0.0f;
                _player.Dispose();
                _player = null;
                MessagingCenter.Send("", PlayerPage.message_dismiss);
            };

            image                 = new UIImage("pause_white.png");
            frame                 = new CGRect(15, View.Frame.Height - 40, 30, 30);
            PlayPauseButton       = new UIButton(UIButtonType.RoundedRect);
            PlayPauseButton.Frame = frame;
            PlayPauseButton.SetImage(image, UIControlState.Normal);
            PlayPauseButton.TouchUpInside += delegate {
                if (_player.Rate == 1.0f)
                {
                    _player.Pause();
                    PlayPauseButton.SetImage(new UIImage("play_white.png"), UIControlState.Normal);
                }
                else
                {
                    _player.Play();
                    PlayPauseButton.SetImage(new UIImage("pause_white.png"), UIControlState.Normal);
                }
            };
            PlayPauseButton.Transform = CGAffineTransform.MakeRotation(M_PI / (nfloat)2.0);

            image               = UIImage.FromBundle("restart_white.png");
            frame               = new CGRect(55, View.Frame.Height - 40, 30, 30);
            RefreshButton       = new UIButton(UIButtonType.RoundedRect);
            RefreshButton.Frame = frame;
            RefreshButton.SetImage(image, UIControlState.Normal);
            RefreshButton.TouchUpInside += delegate {
                CMTime time = new CoreMedia.CMTime();
                CoreMedia.CMTime.FromSeconds(10, 600);

                time.Value = 0;
                _player.CurrentItem.Seek(CoreMedia.CMTime.FromSeconds(0.5, 600));
            };


            View.Add(CloseButton);
            View.Add(PlayPauseButton);
            View.Add(RefreshButton);
        }
Example #4
0
        /// <summary>
        /// Rotates ContentView and rotate it to landscape and play the video.
        /// </summary>
        private void rotateAndPlay(UIViewController controller)
        {
            if (_player.Rate == 0.0)
            {
                _playerLayer = AVPlayerLayer.FromPlayer(_player);
                controller.View.BackgroundColor = UIKit.UIColor.Black;                //new CoreGraphics.CGColor (0f, 0f, 0f);

                CGRect vFrame = new CGRect();
                vFrame.Width  = View.Frame.Height;
                vFrame.Height = View.Frame.Width;

                _playerLayer.Frame        = vFrame;
                _playerLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill;

                controller.View.Layer.AddSublayer(_playerLayer);
                controller.View.Layer.AddSublayer(CloseButton.Layer);
                controller.View.Layer.AddSublayer(PlayPauseButton.Layer);
                controller.View.Layer.AddSublayer(RefreshButton.Layer);



                _playerLayer.Transform = CATransform3D.MakeRotation(90.0f / 180.0f * M_PI, 0.0f, 0.0f, 1.0f);

                vFrame   = _playerLayer.Frame;
                vFrame.X = 0;
                vFrame.Y = 0;

                _playerLayer.Frame = vFrame;

                _player.Play();
            }
            else
            {
                CMTime time = new CoreMedia.CMTime();
                CoreMedia.CMTime.FromSeconds(10, 600);

                time.Value = 0;
                _player.CurrentItem.Seek(CoreMedia.CMTime.FromSeconds(0.5, 600));
            }
        }
Example #5
0
 extern static /* CFStringRef */ IntPtr CMTimeCopyDescription(/* CFAllocatorRef */ IntPtr allocator, CMTime time);
Example #6
0
 public static CMTime Fold(CMTime time, CMTimeRange foldRange)
 {
     return(CMTimeFoldIntoRange(time, foldRange));
 }
Example #7
0
 public static CMTime GetMinimum(CMTime time1, CMTime time2)
 {
     return(CMTimeMinimum(time1, time2));
 }
Example #8
0
 extern static /* Float64 */ double CMTimeGetSeconds(CMTime time);
Example #9
0
 public static CMTime Multiply(CMTime time, int multiplier, int divisor)
 {
     return(CMTimeMultiplyByRatio(time, multiplier, divisor));
 }
Example #10
0
 public static CMTime Multiply(CMTime time, double multiplier)
 {
     return(CMTimeMultiplyByFloat64(time, multiplier));
 }
Example #11
0
 extern static CMTime CMTimeAbsoluteValue(CMTime time);
Example #12
0
 public CMClockError GetAnchorTime(out CMTime clockTime, out CMTime referenceClockTime)
 {
     return(CMClockGetAnchorTime(Handle, out clockTime, out referenceClockTime));
 }
Example #13
0
 extern static /* OSStatus */ CMClockError CMClockGetAnchorTime(/* CMClockRef */ IntPtr clock, out CMTime outClockTime, out CMTime outReferenceClockTime);
Example #14
0
 extern static CMTime CMSyncConvertTime(CMTime time, /* CMClockOrTimebaseRef */ IntPtr fromClockOrTimebase, /* CMClockOrTimebaseRef */ IntPtr toClockOrTimebase);
Example #15
0
        public static CMSyncError GetRelativeRateAndAnchorTime(CMClockOrTimebase clockOrTimebaseA, CMClockOrTimebase clockOrTimebaseB, out double relativeRate, out CMTime timeA, out CMTime timeB)
        {
            if (clockOrTimebaseA == null)
            {
                throw new ArgumentNullException("clockOrTimebaseA");
            }

            if (clockOrTimebaseB == null)
            {
                throw new ArgumentNullException("clockOrTimebaseB");
            }

            return(CMSyncGetRelativeRateAndAnchorTime(clockOrTimebaseA.Handle, clockOrTimebaseB.handle, out relativeRate, out timeA, out timeB));
        }
Example #16
0
 public static CMTime Multiply(CMTime time, int multiplier)
 {
     return(CMTimeMultiply(time, multiplier));
 }
Example #17
0
 extern static CMTime CMTimeMultiplyByFloat64(CMTime time, /* Float64 */ double multiplier);
Example #18
0
 extern static /* int32_t */ int CMTimeCompare(CMTime time1, CMTime time2);
Example #19
0
 extern static CMTime CMTimeMultiplyByRatio(CMTime time, /* int32_t */ int multiplier, /* int32_t */ int divisor);
Example #20
0
 public static int Compare(CMTime time1, CMTime time2)
 {
     return(CMTimeCompare(time1, time2));
 }
Example #21
0
 extern static CMTime CMTimeConvertScale(CMTime time, /* int32_t */ int newScale, CMTimeRoundingMethod method);
Example #22
0
 extern static CMTime CMTimeAdd(CMTime addend1, CMTime addend2);
Example #23
0
 extern static CMTime CMTimeMinimum(CMTime time1, CMTime time2);
Example #24
0
 public static CMTime Add(CMTime time1, CMTime time2)
 {
     return(CMTimeAdd(time1, time2));
 }
Example #25
0
 extern static CMTime CMTimeFoldIntoRange(CMTime time, CMTimeRange foldRange);
Example #26
0
 extern static CMTime CMTimeSubtract(CMTime minuend, CMTime subtrahend);
Example #27
0
 extern static /* CFDictionaryRef */ IntPtr CMTimeCopyAsDictionary(CMTime time, /* CFAllocatorRef */ IntPtr allocator);
Example #28
0
 public static CMTime Subtract(CMTime minuend, CMTime subtraend)
 {
     return(CMTimeSubtract(minuend, subtraend));
 }
Example #29
0
 void HandleAction(CoreMedia.CMTime obj)
 {
 }
Example #30
0
 extern static CMTime CMTimeMultiply(CMTime time, /* int32_t */ int multiplier);