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()); }
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(); }
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); }
/// <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)); } }
extern static /* CFStringRef */ IntPtr CMTimeCopyDescription(/* CFAllocatorRef */ IntPtr allocator, CMTime time);
public static CMTime Fold(CMTime time, CMTimeRange foldRange) { return(CMTimeFoldIntoRange(time, foldRange)); }
public static CMTime GetMinimum(CMTime time1, CMTime time2) { return(CMTimeMinimum(time1, time2)); }
extern static /* Float64 */ double CMTimeGetSeconds(CMTime time);
public static CMTime Multiply(CMTime time, int multiplier, int divisor) { return(CMTimeMultiplyByRatio(time, multiplier, divisor)); }
public static CMTime Multiply(CMTime time, double multiplier) { return(CMTimeMultiplyByFloat64(time, multiplier)); }
extern static CMTime CMTimeAbsoluteValue(CMTime time);
public CMClockError GetAnchorTime(out CMTime clockTime, out CMTime referenceClockTime) { return(CMClockGetAnchorTime(Handle, out clockTime, out referenceClockTime)); }
extern static /* OSStatus */ CMClockError CMClockGetAnchorTime(/* CMClockRef */ IntPtr clock, out CMTime outClockTime, out CMTime outReferenceClockTime);
extern static CMTime CMSyncConvertTime(CMTime time, /* CMClockOrTimebaseRef */ IntPtr fromClockOrTimebase, /* CMClockOrTimebaseRef */ IntPtr toClockOrTimebase);
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)); }
public static CMTime Multiply(CMTime time, int multiplier) { return(CMTimeMultiply(time, multiplier)); }
extern static CMTime CMTimeMultiplyByFloat64(CMTime time, /* Float64 */ double multiplier);
extern static /* int32_t */ int CMTimeCompare(CMTime time1, CMTime time2);
extern static CMTime CMTimeMultiplyByRatio(CMTime time, /* int32_t */ int multiplier, /* int32_t */ int divisor);
public static int Compare(CMTime time1, CMTime time2) { return(CMTimeCompare(time1, time2)); }
extern static CMTime CMTimeConvertScale(CMTime time, /* int32_t */ int newScale, CMTimeRoundingMethod method);
extern static CMTime CMTimeAdd(CMTime addend1, CMTime addend2);
extern static CMTime CMTimeMinimum(CMTime time1, CMTime time2);
public static CMTime Add(CMTime time1, CMTime time2) { return(CMTimeAdd(time1, time2)); }
extern static CMTime CMTimeFoldIntoRange(CMTime time, CMTimeRange foldRange);
extern static CMTime CMTimeSubtract(CMTime minuend, CMTime subtrahend);
extern static /* CFDictionaryRef */ IntPtr CMTimeCopyAsDictionary(CMTime time, /* CFAllocatorRef */ IntPtr allocator);
public static CMTime Subtract(CMTime minuend, CMTime subtraend) { return(CMTimeSubtract(minuend, subtraend)); }
void HandleAction(CoreMedia.CMTime obj) { }
extern static CMTime CMTimeMultiply(CMTime time, /* int32_t */ int multiplier);