/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2011, Nitobi Software Inc.
* Copyright (c) 2011, Microsoft Corporation
* Copyright (c) 2011, Sergey Grebnov.
*/
using System;
using System.IO;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
namespace WP7GapClassLib.PhoneGap.UI
{
///
/// Allows an application to launch the Video Recording application.
/// Use this to allow users to record video from your application.
///
public class VideoCaptureTask
{
///
/// Represents recorded video returned from a call to the Show method of
/// a WP7GapClassLib.PhoneGap.Controls.VideoCaptureTask object
///
public class VideoResult : TaskEventArgs
{
///
/// Initializes a new instance of the VideoResult class.
///
public VideoResult()
{ }
///
/// Initializes a new instance of the VideoResult class
/// with the specified Microsoft.Phone.Tasks.TaskResult.
///
/// Associated Microsoft.Phone.Tasks.TaskResult
public VideoResult(TaskResult taskResult)
: base(taskResult)
{ }
///
/// Gets the file name of the recorded Video.
///
public Stream VideoFile { get; internal set; }
///
/// Gets the stream containing the data for the recorded Video.
///
public string VideoFileName { get; internal set; }
}
///
/// Occurs when a Video recording task is completed.
///
public event EventHandler Completed;
///
/// Shows Video Recording application
///
public void Show()
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var root = Application.Current.RootVisual as PhoneApplicationFrame;
root.Navigated += new System.Windows.Navigation.NavigatedEventHandler(NavigationService_Navigated);
// dummy parameter is used to always open a fresh version
root.Navigate(new System.Uri("/WP7GapClassLib;component/PhoneGap/UI/VideoRecorder.xaml?dummy=" + Guid.NewGuid().ToString(), UriKind.Relative));
});
}
///
/// Performs additional configuration of the recording application.
///
private void NavigationService_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
if (!(e.Content is VideoRecorder)) return;
(Application.Current.RootVisual as PhoneApplicationFrame).Navigated -= NavigationService_Navigated;
VideoRecorder VideoRecorder = (VideoRecorder)e.Content;
if (VideoRecorder != null)
{
VideoRecorder.Completed += this.Completed;
}
else if (this.Completed != null)
{
this.Completed(this, new VideoResult(TaskResult.Cancel));
}
}
}
}