You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/08/15 00:48:46 UTC
[2/9] git commit: [Windows8][CB-4447] Added Windows8 support
[Windows8][CB-4447] Added Windows8 support
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/commit/c747de2b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/c747de2b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/c747de2b
Branch: refs/heads/dev
Commit: c747de2bb9e17b59e3a04cf54829c316df927b46
Parents: 55d31b8
Author: purplecabbage <pu...@gmail.com>
Authored: Tue Jul 30 18:07:45 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Tue Jul 30 18:07:45 2013 -0700
----------------------------------------------------------------------
plugin.xml | 15 ++++
src/windows8/CaptureProxy.js | 161 ++++++++++++++++++++++++++++++++++++++
src/windows8/MediaFile.js | 65 +++++++++++++++
3 files changed, 241 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/c747de2b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index b911bfc..40a568f 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -4,11 +4,13 @@
id="org.apache.cordova.core.media-capture"
version="0.1.0">
<name>Capture</name>
+
<description>Cordova Media Capture Plugin</description>
<license>Apache</license>
<keywords>cordova,media,capture</keywords>
<dependency id="org.apache.cordova.core.file" url="https://git-wip-us.apache.org/repos/asf/cordova-plugin-file" commit="master" subdir="/*" />
+
<js-module src="www/CaptureAudioOptions.js" name="CaptureAudioOptions">
<clobbers target="CaptureAudioOptions" />
@@ -125,5 +127,18 @@
<source-file src="src/wp/UI/VideoRecorder.xaml" />
<source-file src="src/wp/UI/VideoRecorder.xaml.cs" />
</platform>
+
+ <!-- windows8 -->
+ <platform name="windows8">
+
+ <js-module src="src/windows8/MediaFile.js" name="MediaFile2">
+ <clobbers target="MediaFile" />
+ </js-module>
+
+ <js-module src="src/windows8/CaptureProxy.js" name="CaptureProxy">
+ <merges target="" />
+ </js-module>
+
+ </platform>
</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/c747de2b/src/windows8/CaptureProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/CaptureProxy.js b/src/windows8/CaptureProxy.js
new file mode 100644
index 0000000..43c0faa
--- /dev/null
+++ b/src/windows8/CaptureProxy.js
@@ -0,0 +1,161 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/*global Windows:true */
+
+var MediaFile = require('org.apache.cordova.core.media-capture.MediaFile');
+var CaptureError = require('org.apache.cordova.core.media-capture.CaptureError');
+var CaptureAudioOptions = require('org.apache.cordova.core.media-capture.CaptureAudioOptions');
+var CaptureImageOptions = require('org.apache.cordova.core.media-capture.CaptureImageOptions');
+var CaptureVideoOptions = require('org.apache.cordova.core.media-capture.CaptureVideoOptions');
+var MediaFileData = require('org.apache.cordova.core.media-capture.MediaFileData');
+
+module.exports = {
+
+ captureAudio:function(successCallback, errorCallback, args) {
+ var options = args[0];
+
+ var audioOptions = new CaptureAudioOptions();
+ if (typeof(options.duration) == 'undefined') {
+ audioOptions.duration = 3600; // Arbitrary amount, need to change later
+ } else if (options.duration > 0) {
+ audioOptions.duration = options.duration;
+ } else {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ return;
+ }
+
+ var cameraCaptureAudioDuration = audioOptions.duration;
+ var mediaCaptureSettings;
+ var initCaptureSettings = function () {
+ mediaCaptureSettings = null;
+ mediaCaptureSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
+ mediaCaptureSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
+ };
+
+ initCaptureSettings();
+ var mediaCapture = new Windows.Media.Capture.MediaCapture();
+ mediaCapture.initializeAsync(mediaCaptureSettings).done(function () {
+ Windows.Storage.KnownFolders.musicLibrary.createFileAsync("captureAudio.mp3", Windows.Storage.NameCollisionOption.generateUniqueName).then(function (storageFile) {
+ var mediaEncodingProfile = new Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.auto);
+ var stopRecord = function () {
+ mediaCapture.stopRecordAsync().then(function (result) {
+ storageFile.getBasicPropertiesAsync().then(function (basicProperties) {
+ var results = [];
+ results.push(new MediaFile(storageFile.name, storageFile.path, storageFile.contentType, basicProperties.dateModified, basicProperties.size));
+ successCallback(results);
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
+ });
+ }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
+ };
+ mediaCapture.startRecordToStorageFileAsync(mediaEncodingProfile, storageFile).then(function () {
+ setTimeout(stopRecord, cameraCaptureAudioDuration * 1000);
+ }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
+ }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
+ });
+ },
+
+ captureImage:function (successCallback, errorCallback, args) {
+ var options = args[0];
+ var imageOptions = new CaptureImageOptions();
+ var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
+ cameraCaptureUI.photoSettings.allowCropping = true;
+ cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
+ cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
+ cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (file) {
+ file.moveAsync(Windows.Storage.KnownFolders.picturesLibrary, "cameraCaptureImage.jpg", Windows.Storage.NameCollisionOption.generateUniqueName).then(function () {
+ file.getBasicPropertiesAsync().then(function (basicProperties) {
+ var results = [];
+ results.push(new MediaFile(file.name, file.path, file.contentType, basicProperties.dateModified, basicProperties.size));
+ successCallback(results);
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
+ });
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
+ });
+ }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
+ },
+
+ captureVideo:function (successCallback, errorCallback, args) {
+ var options = args[0];
+ var videoOptions = new CaptureVideoOptions();
+ if (options.duration && options.duration > 0) {
+ videoOptions.duration = options.duration;
+ }
+ if (options.limit > 1) {
+ videoOptions.limit = options.limit;
+ }
+ var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
+ cameraCaptureUI.videoSettings.allowTrimming = true;
+ cameraCaptureUI.videoSettings.format = Windows.Media.Capture.CameraCaptureUIVideoFormat.mp4;
+ cameraCaptureUI.videoSettings.maxDurationInSeconds = videoOptions.duration;
+ cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.video).then(function (file) {
+ file.moveAsync(Windows.Storage.KnownFolders.videosLibrary, "cameraCaptureVedio.mp4", Windows.Storage.NameCollisionOption.generateUniqueName).then(function () {
+ file.getBasicPropertiesAsync().then(function (basicProperties) {
+ var results = [];
+ results.push(new MediaFile(file.name, file.path, file.contentType, basicProperties.dateModified, basicProperties.size));
+ successCallback(results);
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
+ });
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
+ });
+ }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
+
+ },
+
+ getFormatData: function (successCallback, errorCallback, args) {
+ Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
+ function (storageFile) {
+ var mediaTypeFlag = String(storageFile.contentType).split("/")[0].toLowerCase();
+ if (mediaTypeFlag === "audio") {
+ storageFile.properties.getMusicPropertiesAsync().then(function (audioProperties) {
+ successCallback(new MediaFileData(null, audioProperties.bitrate, 0, 0, audioProperties.duration / 1000));
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ });
+ }
+ else if (mediaTypeFlag === "video") {
+ storageFile.properties.getVideoPropertiesAsync().then(function (videoProperties) {
+ successCallback(new MediaFileData(null, videoProperties.bitrate, videoProperties.height, videoProperties.width, videoProperties.duration / 1000));
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ });
+ }
+ else if (mediaTypeFlag === "image") {
+ storageFile.properties.getImagePropertiesAsync().then(function (imageProperties) {
+ successCallback(new MediaFileData(null, 0, imageProperties.height, imageProperties.width, 0));
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ });
+ }
+ else { errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT)); }
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ }
+ );
+ }
+};
+
+require("cordova/commandProxy").add("Capture",module.exports);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/c747de2b/src/windows8/MediaFile.js
----------------------------------------------------------------------
diff --git a/src/windows8/MediaFile.js b/src/windows8/MediaFile.js
new file mode 100644
index 0000000..34ecba2
--- /dev/null
+++ b/src/windows8/MediaFile.js
@@ -0,0 +1,65 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/*global Windows:true */
+
+var MediaFileData = require('org.apache.cordova.core.media-capture.MediaFileData');
+var CaptureError = require('org.apache.cordova.core.media-capture.CaptureError');
+
+module.exports = {
+
+ getFormatData: function (successCallback, errorCallback, args) {
+ Windows.Storage.StorageFile.getFileFromPathAsync(this.fullPath).then(
+ function (storageFile) {
+ var mediaTypeFlag = String(storageFile.contentType).split("/")[0].toLowerCase();
+ if (mediaTypeFlag === "audio") {
+ storageFile.properties.getMusicPropertiesAsync().then(
+ function (audioProperties) {
+ successCallback(new MediaFileData(null, audioProperties.bitrate, 0, 0, audioProperties.duration / 1000));
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ }
+ );
+ } else if (mediaTypeFlag === "video") {
+ storageFile.properties.getVideoPropertiesAsync().then(
+ function (videoProperties) {
+ successCallback(new MediaFileData(null, videoProperties.bitrate, videoProperties.height, videoProperties.width, videoProperties.duration / 1000));
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ }
+ );
+ } else if (mediaTypeFlag === "image") {
+ storageFile.properties.getImagePropertiesAsync().then(
+ function (imageProperties) {
+ successCallback(new MediaFileData(null, 0, imageProperties.height, imageProperties.width, 0));
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ }
+ );
+ } else {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ }
+ }, function () {
+ errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+ }
+ );
+ }
+};