[MediaCapture] fix docdir for iOS8

This commit is contained in:
Rustam Zaitov 2015-05-11 21:31:12 +03:00
Родитель a3caf2a40d
Коммит 7cd48d472e
3 изменённых файлов: 71 добавлений и 100 удалений

Просмотреть файл

@ -42,7 +42,6 @@ namespace MediaCapture
// log message
UITextView textView = null;
ConcurrentQueue<string> messages = new ConcurrentQueue<string>();
int textViewXOffset;
int textViewYOffset;
int textViewWidth;
@ -407,12 +406,12 @@ namespace MediaCapture
try
{
var player = new MPMoviePlayerController();
player = new MPMoviePlayerController (NSUrl.FromFilename( args.File ));
player.AllowsAirPlay = true;
View.AddSubview(player.View);
player.SetFullscreen(true, true);
var player = new MPMoviePlayerController (NSUrl.FromFilename( args.File ));
NavigationController.PushViewController(player, true);
player.AllowsAirPlay = false;
player.PrepareToPlay();
// player.View.Frame = View.Bounds;
// View.AddSubview(player.View);
player.Play();
}
catch ( Exception ex )
@ -496,20 +495,13 @@ namespace MediaCapture
// this is a poor man's message logger. This really should be in a table view but this is just a sample app so ...
void LogMessage(string message )
{
DateTime time = DateTime.Now;
string timeText = string.Format ("{0}:{1}:{2}.{3}", time.Hour, time.Minute.ToString().PadLeft(2,'0'), time.Second.ToString().PadLeft(2,'0'), time.Millisecond);
string timeStampedMessage = string.Format ("{0}: {1}\r\n", timeText , message.TrimEnd());
messages.Enqueue( timeStampedMessage );
string timeText = DateTime.Now.ToString("HH:mm:ss.ff");
string timeStampedMessage = string.Format ("{0}: {1}{2}", timeText , message.Trim(), Environment.NewLine);
StringBuilder sb = new StringBuilder();
string [] messageArray = messages.ToArray();
foreach ( string m in messageArray )
sb.Append(m);
string text = sb.ToString();
InvokeOnMainThread(() => {
textView.Text = text;
ScrollMessageViewToEnd();
InvokeOnMainThread (() => {
var sb = new StringBuilder (textView.Text).AppendLine (timeStampedMessage);
textView.Text = sb.ToString ();
ScrollMessageViewToEnd ();
});
}

Просмотреть файл

@ -13,6 +13,7 @@
using System;
using System.IO;
using Foundation;
using System.Linq;
namespace MediaCapture
{
@ -96,6 +97,38 @@ namespace MediaCapture
}
}
static NSUrl DocumentsDir {
get {
return NSFileManager.DefaultManager
.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)
.Last();
}
}
static string configDirectory = null;
public static string ConfigDirectory {
get {
configDirectory = configDirectory ?? CreateDirectoryIfNeeded (Path.Combine (DocumentsDir.Path, "Config"));
return configDirectory;
}
}
static string videoDataPath = null;
public static string VideoDataPath {
get {
videoDataPath = videoDataPath ?? CreateDirectoryIfNeeded (Path.Combine (DocumentsDir.Path, "VideoData"));
return videoDataPath;
}
}
static string imageDataPath = null;
public static string ImageDataPath {
get {
imageDataPath = imageDataPath ?? CreateDirectoryIfNeeded (Path.Combine (DocumentsDir.Path, "ImageData"));
return imageDataPath;
}
}
public void Load()
{
bool isFirstSettingsLoad = (NSUserDefaults.StandardUserDefaults.BoolForKey( SettingsNames.HaveSettingsBeenLoadedBefore.ToString() ) == false);
@ -134,51 +167,16 @@ namespace MediaCapture
NSUserDefaults.StandardUserDefaults.Synchronize();
}
static string CreateDirectoryIfNeeded( string directory )
static string CreateDirectoryIfNeeded(string directory)
{
if (Directory.Exists(directory) == false)
Directory.CreateDirectory( directory );
var fm = NSFileManager.DefaultManager;
if (!fm.FileExists (directory)) {
NSError error;
if(!fm.CreateDirectory (directory, false, (NSFileAttributes)null, out error))
Console.WriteLine (error);
}
return directory;
}
static string myDocuments = null;
public static string MyDocuments {
get {
// TODO: This doesn't work on iOS8
if ( myDocuments == null )
myDocuments = CreateDirectoryIfNeeded( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) );
return myDocuments;
}
}
static string configDirectory = null;
public static string ConfigDirectory {
get {
// TODO: This doesn't work on iOS8
if ( configDirectory == null )
configDirectory = CreateDirectoryIfNeeded( Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Config" ) );
return configDirectory;
}
}
static string videoDataPath = null;
public static string VideoDataPath {
get {
// TODO: This doesn't work on iOS8
if ( videoDataPath == null )
videoDataPath = CreateDirectoryIfNeeded( Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VideoData" ) );
return videoDataPath;
}
}
static string imageDataPath = null;
public static string ImageDataPath {
get {
// TODO: This doesn't work on iOS8
if ( imageDataPath == null )
imageDataPath = CreateDirectoryIfNeeded( Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ImageData" ) );
return imageDataPath;
}
}
}
}

Просмотреть файл

@ -216,53 +216,34 @@ namespace MediaCapture
void BuildActionElements()
{
deleteMoviesElement = new StringElement("Delete Movies");
deleteMoviesElement.Tapped += delegate
{
try
{
Directory.Delete( Settings.VideoDataPath, true );
}
catch
{
}
deleteMoviesElement.Tapped += () => {
Directory.Delete( Settings.VideoDataPath, true );
};
deleteImagesElement = new StringElement("Delete Images");
deleteImagesElement.Tapped += delegate
{
try
{
Directory.Delete( Settings.ImageDataPath, true );
}
catch
{
}
deleteImagesElement.Tapped += () => {
Directory.Delete( Settings.ImageDataPath, true );
};
}
public void EnforceDependencies()
{
try
{
// image capture save is not relevant if no images are being captured
if ( imageCaptureEnabledElement.Value == false )
{
saveImageGroup.Selected = 0;
}
saveImageElement.GetActiveCell().UserInteractionEnabled = imageCaptureEnabledElement.Value;
// image capture save is not relevant if no images are being captured
if ( imageCaptureEnabledElement.Value == false )
saveImageGroup.Selected = 0;
// looped recordings and duration are not relevant unless something is being recorded
bool isMediaCaptureEnebled = ( audioCaptureEnabledElement.Value || videoCaptureEnabledElement.Value );
if ( isMediaCaptureEnebled == false )
{
autoRecordNextMovieElement.Value = false;
}
autoRecordNextMovieElement.GetActiveCell().UserInteractionEnabled = isMediaCaptureEnebled;
durationElement.GetActiveCell().UserInteractionEnabled = isMediaCaptureEnebled;
}
catch
{
}
UITableViewCell activeCell = saveImageElement.GetActiveCell ();
if(activeCell == null)
return;
activeCell.UserInteractionEnabled = imageCaptureEnabledElement.Value;
// looped recordings and duration are not relevant unless something is being recorded
bool isMediaCaptureEnebled = ( audioCaptureEnabledElement.Value || videoCaptureEnabledElement.Value );
if ( isMediaCaptureEnebled == false )
autoRecordNextMovieElement.Value = false;
autoRecordNextMovieElement.GetActiveCell().UserInteractionEnabled = isMediaCaptureEnebled;
durationElement.GetActiveCell().UserInteractionEnabled = isMediaCaptureEnebled;
}
public Settings ResultSettings {