public MainWindow() { Current = this; LibraryItems = new ObservableCollection <LibraryItem>() { new LibraryItem(LibraryItem.LibraryItemName.Songs), new LibraryItem(LibraryItem.LibraryItemName.Artists), new LibraryItem(LibraryItem.LibraryItemName.Albums) }; MediaUtils.LoadAndSortSongs(); MediaUtils.LoadPlaylists(); MediaUtils.SongsCurrentlySelected = MediaUtils.AllSongs; DataContext = this; InitializeComponent(); MediaUtils.MediaElement = mePlayer; lvPlaylists.ItemsSource = MediaUtils.Playlists; pageFrame.CurrentPage = new SongsPage(MediaUtils.AllSongs); faPlayPause.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Play; DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += CheckUserInput; dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); }
private void ExtractVideoPickedFromGallery(Intent data) { try { Android.Net.Uri selectedUri = data.Data; string mimeType = "video"; PickedMediaFromGallery result = new PickedMediaFromGallery(); if (mimeType.StartsWith("video")) { string filePath = MediaUtils.GetFileFullPathAlternativeVideo(data.Data, this); Java.IO.File videoFile = new Java.IO.File(filePath); Java.IO.FileInputStream videoFileInputStream = new Java.IO.FileInputStream(videoFile); byte[] videoFileBytes = new byte[videoFile.Length()]; videoFileInputStream.Read(videoFileBytes); videoFileInputStream.Close(); videoFileInputStream.Dispose(); System.IO.Stream thumbnailStream = DependencyService.Get <IPickMediaDependencyService>().GetThumbnail(filePath); byte[] thumbnailBytes; thumbnailStream.Position = 0; using (System.IO.BinaryReader reader = new System.IO.BinaryReader(thumbnailStream)) { thumbnailBytes = reader.ReadBytes((int)thumbnailStream.Length); } result = new PickedMediaFromGallery() { Completion = true, DataBase64 = Android.Util.Base64.EncodeToString(videoFileBytes, Android.Util.Base64Flags.Default), DataThumbnailBase64 = Convert.ToBase64String(thumbnailBytes), FilePath = filePath, MimeType = ProfileMediaService.VIDEO_MEDIA_TYPE }; } else { Debugger.Break(); throw new InvalidOperationException(); } PickVideoTaskCompletion.SetResult(result); } catch (Exception exc) { Debugger.Break(); PickVideoTaskCompletion.SetResult(new PickedMediaFromGallery() { Exception = exc, ErrorMessage = _EXTRACTION_MEDIA_MEDIA_PICK_ERROR }); } }
private void mePlayer_OnMediaEnded(object sender, RoutedEventArgs e) { if (MediaUtils.IsNextEnabled) { MediaUtils.Next(); } else { MediaUtils.Stop(); } }
private IProducer <CloseableReference <CloseableImage> > GetBasicDecodedImageSequence( ImageRequest imageRequest) { Preconditions.CheckNotNull(imageRequest); Uri uri = imageRequest.SourceUri; Preconditions.CheckNotNull(uri, "Uri is null."); if (UriUtil.IsNetworkUri(uri)) { return(GetNetworkFetchSequence()); } else if (UriUtil.IsAppDataUri(uri)) { if (MediaUtils.IsVideo(MediaUtils.ExtractMime(uri.ToString()))) { return(GetLocalVideoFileFetchSequence()); } else { return(GetLocalImageFileFetchSequence()); } } else if (UriUtil.IsAppPackageUri(uri)) { return(GetLocalAssetFetchSequence()); } else if (UriUtil.IsAppResourceUri(uri)) { return(GetLocalResourceFetchSequence()); } else if (UriUtil.IsDataUri(uri)) { return(GetDataFetchSequence()); } else if (UriUtil.IsFileUri(uri)) { return(GetLocalImageFileFetchSequence()); } else if (UriUtil.IsFutureAccessListUri(uri)) { return(GetFutureAccessListFetchSequence()); } else { string uriString = uri.ToString(); if (uriString.Length > 30) { uriString = uriString.Substring(0, 30) + "..."; } throw new Exception("Unsupported uri scheme! Uri is: " + uriString); } }
private void btnPlayPause_Click(object sender, RoutedEventArgs e) { if (MediaUtils.IsPlaying) { MediaUtils.Pause(); } else { if (MediaUtils.CurrentSong == null) { MediaUtils.SongsCurrentlySelected.First().Play(true); } else { MediaUtils.CurrentSong.Play(); } } }
private void ExtractVideoTakedFromCamera(Intent data) { try { Android.Net.Uri selectedUri = data.Data; string filePath = MediaUtils.GetFileFullPathAlternativeVideo(data.Data, this); Java.IO.File videoFile = new Java.IO.File(filePath); Java.IO.FileInputStream videoFileInputStream = new Java.IO.FileInputStream(videoFile); byte[] videoFileBytes = new byte[videoFile.Length()]; videoFileInputStream.Read(videoFileBytes); videoFileInputStream.Close(); videoFileInputStream.Dispose(); System.IO.Stream thumbnailStream = DependencyService.Get <IPickMediaDependencyService>().GetThumbnail(filePath); byte[] thumbnailBytes; thumbnailStream.Position = 0; using (System.IO.BinaryReader reader = new System.IO.BinaryReader(thumbnailStream)) { thumbnailBytes = reader.ReadBytes((int)thumbnailStream.Length); } CompleteActionTakeVideoOrImage(new PickedMediaFromGallery() { Completion = true, DataBase64 = Android.Util.Base64.EncodeToString(videoFileBytes, Android.Util.Base64Flags.Default), DataThumbnailBase64 = Convert.ToBase64String(thumbnailBytes), FilePath = filePath, MimeType = ProfileMediaService.VIDEO_MEDIA_TYPE }); } catch (Exception exc) { CompleteActionTakeVideoOrImage(new PickedMediaFromGallery() { Exception = exc, ErrorMessage = _TAKE_VIDEO_OR_IMAGE_TAKED_VIDEO_HANDLING_ERROR }); } }
private void Application_Startup(object sender, StartupEventArgs e) { MediaUtils.MediaFoundationStartup(); }
private void Application_Exit(object sender, ExitEventArgs e) { try { MediaUtils.MediaFoundationShutdown(); } catch { } }
private void OnVideoMediaReceived(object sender, VideoMediaReceivedEventArgs e) { try { CorrelationId.SetCurrentId(_correlationId); if (DateTime.Now > this._lastVideoCapturedTimeUtc + this.VideoCaptureFrequency) { // Update the last capture timestamp this._lastVideoCapturedTimeUtc = DateTime.Now; Log.Info( new CallerInfo(), LogContext.Media, "[{0}]: Capturing image: [VideoMediaReceivedEventArgs(Data=<{1}>, Length={2}, Timestamp={3}, Width={4}, Height={5}, ColorFormat={6}, FrameRate={7})]", this.Id, e.Buffer.Data.ToString(), e.Buffer.Length, e.Buffer.Timestamp, e.Buffer.VideoFormat.Width, e.Buffer.VideoFormat.Height, e.Buffer.VideoFormat.VideoColorFormat, e.Buffer.VideoFormat.FrameRate); // Make a copy of the media buffer Stopwatch watch = new Stopwatch(); watch.Start(); byte[] buffer = new byte[e.Buffer.Length]; Marshal.Copy(e.Buffer.Data, buffer, 0, (int)e.Buffer.Length); VideoMediaBuffer videoRenderMediaBuffer = e.Buffer as VideoMediaBuffer; IntPtr ptrToBuffer = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, ptrToBuffer, buffer.Length); watch.Stop(); Log.Info(new CallerInfo(), LogContext.Media, $"{this.Id} Took {watch.ElapsedMilliseconds} ms to copy buffer"); // Transform to bitmap object Bitmap bmpObject = MediaUtils.TransformNV12ToBmpFaster(buffer, e.Buffer.VideoFormat.Width, e.Buffer.VideoFormat.Height); bool sendChatMessage = (CurrentVideoImage == null); Log.Info(new CallerInfo(), LogContext.Media, $"{this.Id} send chat message {sendChatMessage}"); // 3. Update the bitmap cache CurrentVideoImage = bmpObject; if (sendChatMessage) { Task.Run(async() => { try { await RealTimeMediaCall.SendMessageForCall(RealTimeMediaCall); }catch (Exception ex) { Log.Info(new CallerInfo(), LogContext.FrontEnd, $"Exception in SendingChatMessage {ex}"); } }); } } } catch (Exception ex) { Log.Error(new CallerInfo(), LogContext.Media, $"{this.Id} Exception in VideoMediaReceived {ex.ToString()}"); } e.Buffer.Dispose(); }
private void btnStop_Click(object sender, RoutedEventArgs e) => MediaUtils.Stop();
private void btnPrevious_Click(object sender, RoutedEventArgs e) => MediaUtils.Previous();
private void btnNext_Click(object sender, RoutedEventArgs e) => MediaUtils.Next();
private void MainWindow_Closing(object sender, CancelEventArgs e) => MediaUtils.SavePlaylists();
private void ExtractMediaPickedFromGallery(Intent data) { try { Android.Net.Uri selectedUri = data.Data; String[] columns = { MediaStore.Images.Media.InterfaceConsts.Data, MediaStore.Images.Media.InterfaceConsts.MimeType }; ICursor cursor = ContentResolver.Query(selectedUri, columns, null, null, null); cursor.MoveToFirst(); int pathColumnIndex = cursor.GetColumnIndex(columns[0]); int mimeTypeColumnIndex = cursor.GetColumnIndex(columns[1]); string mimeType = cursor.GetString(mimeTypeColumnIndex); cursor.Close(); PickedMediaFromGallery result = null; if (mimeType.StartsWith("image")) { Android.Graphics.Bitmap bitmap = MediaUtils.GetScaledBitmap( data.Data, MediaUtils.IMAGE_WIDTH_RESTRICTION, MediaUtils.IMAGE_HEIGHT_RESTRICTION, this); if (bitmap == null) { bitmap = MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data); } byte[] bytes; using (MemoryStream memoryStream = new MemoryStream()) { bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, memoryStream); bytes = memoryStream.GetBuffer(); } result = new PickedMediaFromGallery() { DataBase64 = Android.Util.Base64.EncodeToString(bytes, Android.Util.Base64Flags.Default), Completion = true, DataThumbnailBase64 = Android.Util.Base64.EncodeToString(bytes, Android.Util.Base64Flags.Default), MimeType = ProfileMediaService.IMAGE_MEDIA_TYPE }; } else if (mimeType.StartsWith("video")) { string filePath = MediaUtils.GetFileFullPathAlternativeVideo(data.Data, this); Java.IO.File videoFile = new Java.IO.File(filePath); Java.IO.FileInputStream videoFileInputStream = new Java.IO.FileInputStream(videoFile); byte[] videoFileBytes = new byte[videoFile.Length()]; videoFileInputStream.Read(videoFileBytes); videoFileInputStream.Close(); videoFileInputStream.Dispose(); System.IO.Stream thumbnailStream = DependencyService.Get <IPickMediaDependencyService>().GetThumbnail(filePath); byte[] thumbnailBytes; thumbnailStream.Position = 0; using (System.IO.BinaryReader reader = new System.IO.BinaryReader(thumbnailStream)) { thumbnailBytes = reader.ReadBytes((int)thumbnailStream.Length); } result = new PickedMediaFromGallery() { Completion = true, DataBase64 = Android.Util.Base64.EncodeToString(videoFileBytes, Android.Util.Base64Flags.Default), DataThumbnailBase64 = Convert.ToBase64String(thumbnailBytes), FilePath = filePath, MimeType = ProfileMediaService.VIDEO_MEDIA_TYPE }; } else { Debugger.Break(); throw new InvalidOperationException(); } PickMediaTaskCompletion.SetResult(result); } catch (Exception exc) { Debugger.Break(); PickMediaTaskCompletion.SetResult(new PickedMediaFromGallery() { Exception = exc, ErrorMessage = _EXTRACTION_MEDIA_MEDIA_PICK_ERROR }); } }