diff --git a/Windows Phone/VineCache/VineCache/ParseLibrary.cs b/Windows Phone/VineCache/VineCache/ParseLibrary.cs index 9710ea4..30d57f3 100644 --- a/Windows Phone/VineCache/VineCache/ParseLibrary.cs +++ b/Windows Phone/VineCache/VineCache/ParseLibrary.cs @@ -318,7 +318,7 @@ public void UploadVideo(byte[] videoData, PLNode node) var video = new ParseObject("Videos"); video["Video"] = file; video["Node"] = node.pfNode; - var relation = node.pfNode.GetRelation("Videos"); + var relation = _PLPlayer.pfPlayer.GetRelation("Videos"); relation.Add(video); node.pfNode.SaveAsync(); } diff --git a/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml.cs b/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml.cs index 3e21e1c..739d934 100644 --- a/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml.cs +++ b/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml.cs @@ -3,12 +3,14 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading.Tasks; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.Media.Capture; using Windows.Media.MediaProperties; using Windows.Phone.UI.Input; using Windows.Storage; +using Windows.Storage.Streams; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; @@ -51,6 +53,9 @@ private async void StartRecordingVideo() StorageFile videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(VideoFileName, CreationCollisionOption.ReplaceExisting); MediaEncodingProfile encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p); await this.mediaCapture.StartRecordToStorageFileAsync(encodingProfile, videoStorageFile); + + await Task.Delay(6000); + StopRecordingVideo(); } } @@ -59,6 +64,34 @@ private async void StopRecordingVideo() await this.mediaCapture.StopRecordAsync(); } + private async void UploadRecordedVideo() + { + StorageFile videoStorageFile = await KnownFolders.VideosLibrary.GetFileAsync(VideoFileName); + if (videoStorageFile != null) + { + byte[] videoData = await ReadFile(videoStorageFile); + App.parseDB.UploadVideo(videoData, ParseDB._PLNodes[App.currentNodeNumba]); + } + } + + /// + /// Loads the byte data from a StorageFile + /// + /// The file to read + private static async Task ReadFile(StorageFile file) + { + byte[] fileBytes = null; + using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync()) + { + fileBytes = new byte[stream.Size]; + using (DataReader reader = new DataReader(stream)) + { + await reader.LoadAsync((uint)stream.Size); + reader.ReadBytes(fileBytes); + } + } + return fileBytes; + } /// /// Invoked when this page is about to be displayed in a Frame. @@ -69,7 +102,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) { this.InitVideoCapture(); } - + private void StartRecordingButton_Click(object sender, RoutedEventArgs e) { StartRecordingVideo(); @@ -77,9 +110,10 @@ private void StartRecordingButton_Click(object sender, RoutedEventArgs e) private void UploadRecordingButton_Click(object sender, RoutedEventArgs e) { - StopRecordingVideo(); + UploadRecordedVideo(); } + private void videoMediaElement_Tapped(object sender, RoutedEventArgs e) {