Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3B4D110748 for ; Wed, 14 Aug 2013 22:46:13 +0000 (UTC) Received: (qmail 69050 invoked by uid 500); 14 Aug 2013 22:46:13 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 69002 invoked by uid 500); 14 Aug 2013 22:46:13 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 68955 invoked by uid 99); 14 Aug 2013 22:46:13 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Aug 2013 22:46:13 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DA1AC836683; Wed, 14 Aug 2013 22:46:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Wed, 14 Aug 2013 22:46:13 -0000 Message-Id: <7637acc363d94e7cb2f8539ae9d391cb@git.apache.org> In-Reply-To: <3323ef3952c34c5ba9fcea2fc58fe68c@git.apache.org> References: <3323ef3952c34c5ba9fcea2fc58fe68c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/7] git commit: [Windows8][CB-4448] Added windows 8 support [Windows8][CB-4448] Added windows 8 support Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/ffac9763 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/ffac9763 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/ffac9763 Branch: refs/heads/dev Commit: ffac9763164854241805a87a6607fd1eefac958c Parents: 788e00f Author: purplecabbage Authored: Tue Jul 30 17:46:01 2013 -0700 Committer: purplecabbage Committed: Tue Jul 30 17:46:01 2013 -0700 ---------------------------------------------------------------------- plugin.xml | 7 ++ src/windows8/MediaProxy.js | 183 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/ffac9763/plugin.xml ---------------------------------------------------------------------- diff --git a/plugin.xml b/plugin.xml index 85dc49c..a0cc4dd 100644 --- a/plugin.xml +++ b/plugin.xml @@ -88,6 +88,13 @@ id="org.apache.cordova.core.AudioHandler" + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/ffac9763/src/windows8/MediaProxy.js ---------------------------------------------------------------------- diff --git a/src/windows8/MediaProxy.js b/src/windows8/MediaProxy.js new file mode 100644 index 0000000..61c0e69 --- /dev/null +++ b/src/windows8/MediaProxy.js @@ -0,0 +1,183 @@ +/* + * + * 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 cordova = require('cordova'), + Media = require('org.apache.cordova.core.AudioHandler.Media'); + +var MediaError = require('org.apache.cordova.core.AudioHandler.MediaError'); + +module.exports = { + mediaCaptureMrg:null, + + // Initiates the audio file + create:function(win, lose, args) { + var id = args[0]; + var src = args[1]; + var thisM = Media.get(id); + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STARTING); + + Media.prototype.node = null; + + var fn = src.split('.').pop(); // gets the file extension + if (thisM.node === null) { + if (fn === 'mp3' || fn === 'wma' || fn === 'wma' || + fn === 'cda' || fn === 'adx' || fn === 'wm' || + fn === 'm3u' || fn === 'wmx') { + thisM.node = new Audio(src); + thisM.node.load(); + var dur = thisM.node.duration; + if (isNaN(dur)) { + dur = -1; + } + Media.onStatus(id, Media.MEDIA_DURATION, dur); + } + else { + lose && lose({code:MediaError.MEDIA_ERR_ABORTED}); + } + } + }, + + // Start playing the audio + startPlayingAudio:function(win, lose, args) { + var id = args[0]; + //var src = args[1]; + //var options = args[2]; + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_RUNNING); + + (Media.get(id)).node.play(); + }, + + // Stops the playing audio + stopPlayingAudio:function(win, lose, args) { + var id = args[0]; + try { + (Media.get(id)).node.pause(); + (Media.get(id)).node.currentTime = 0; + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED); + win(); + } catch (err) { + lose("Failed to stop: "+err); + } + }, + + // Seeks to the position in the audio + seekToAudio:function(win, lose, args) { + var id = args[0]; + var milliseconds = args[1]; + try { + (Media.get(id)).node.currentTime = milliseconds / 1000; + win(); + } catch (err) { + lose("Failed to seek: "+err); + } + }, + + // Pauses the playing audio + pausePlayingAudio:function(win, lose, args) { + var id = args[0]; + var thisM = Media.get(id); + try { + thisM.node.pause(); + Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED); + } catch (err) { + lose("Failed to pause: "+err); + } + }, + + // Gets current position in the audio + getCurrentPositionAudio:function(win, lose, args) { + var id = args[0]; + try { + var p = (Media.get(id)).node.currentTime; + Media.onStatus(id, Media.MEDIA_POSITION, p); + win(p); + } catch (err) { + lose(err); + } + }, + + // Start recording audio + startRecordingAudio:function(win, lose, args) { + var id = args[0]; + var src = args[1]; + // Initialize device + Media.prototype.mediaCaptureMgr = null; + var thisM = (Media.get(id)); + var captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings(); + captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio; + thisM.mediaCaptureMgr = new Windows.Media.Capture.MediaCapture(); + thisM.mediaCaptureMgr.addEventListener("failed", lose); + + thisM.mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result) { + thisM.mediaCaptureMgr.addEventListener("recordlimitationexceeded", lose); + thisM.mediaCaptureMgr.addEventListener("failed", lose); + }, lose); + // Start recording + Windows.Storage.KnownFolders.musicLibrary.createFileAsync(src, Windows.Storage.CreationCollisionOption.replaceExisting).done(function (newFile) { + var storageFile = newFile; + var fileType = this.src.split('.').pop(); + var encodingProfile = null; + switch (fileType) { + case 'm4a': + encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createM4a(Windows.Media.MediaProperties.AudioEncodingQuality.auto); + break; + case 'mp3': + encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp3(Windows.Media.MediaProperties.AudioEncodingQuality.auto); + break; + case 'wma': + encodingProfile = Windows.Media.MediaProperties.MediaEncodingProfile.createWma(Windows.Media.MediaProperties.AudioEncodingQuality.auto); + break; + default: + lose("Invalid file type for record"); + break; + } + thisM.mediaCaptureMgr.startRecordToStorageFileAsync(encodingProfile, storageFile).done(win, lose); + }, lose); + }, + + // Stop recording audio + stopRecordingAudio:function(win, lose, args) { + var id = args[0]; + var thisM = Media.get(id); + thisM.mediaCaptureMgr.stopRecordAsync().done(win, lose); + }, + + // Release the media object + release:function(win, lose, args) { + var id = args[0]; + var thisM = Media.get(id); + try { + delete thisM.node; + } catch (err) { + lose("Failed to release: "+err); + } + }, + setVolume:function(win, lose, args) { + var id = args[0]; + var volume = args[1]; + var thisM = Media.get(id); + thisM.volume = volume; + } +}; + +require("cordova/commandProxy").add("Media",module.exports); \ No newline at end of file