Skip to content

Commit

Permalink
added media plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
playerx committed Feb 26, 2014
1 parent 98231b1 commit b0b47d8
Show file tree
Hide file tree
Showing 34 changed files with 6,621 additions and 8 deletions.
17 changes: 16 additions & 1 deletion Mobile/platforms/ios/.staging/www/cordova_plugins.js
Expand Up @@ -27,6 +27,20 @@ module.exports = [
"merges": [
"navigator.notification"
]
},
{
"file": "plugins/org.apache.cordova.media/www/MediaError.js",
"id": "org.apache.cordova.media.MediaError",
"clobbers": [
"window.MediaError"
]
},
{
"file": "plugins/org.apache.cordova.media/www/Media.js",
"id": "org.apache.cordova.media.Media",
"clobbers": [
"window.Media"
]
}
];
module.exports.metadata =
Expand All @@ -36,7 +50,8 @@ module.exports.metadata =
"org.apache.cordova.dialogs": "0.2.6",
"org.apache.cordova.inappbrowser": "0.3.1",
"org.apache.cordova.vibration": "0.3.7",
"com.phonegap.plugins.jokutils": "0.1.0"
"com.phonegap.plugins.jokutils": "0.1.0",
"org.apache.cordova.media": "0.2.8"
}
// BOTTOM OF METADATA
});
@@ -0,0 +1,197 @@
cordova.define("org.apache.cordova.media.Media", function(require, exports, module) { /*
*
* 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.
*
*/

var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
exec = require('cordova/exec');

var mediaObjects = {};

/**
* This class provides access to the device media, interfaces to both sound and video
*
* @constructor
* @param src The file name or url to play
* @param successCallback The callback to be called when the file is done playing or recording.
* successCallback()
* @param errorCallback The callback to be called if there is an error.
* errorCallback(int errorCode) - OPTIONAL
* @param statusCallback The callback to be called when media status has changed.
* statusCallback(int statusCode) - OPTIONAL
*/
var Media = function(src, successCallback, errorCallback, statusCallback) {
argscheck.checkArgs('SFFF', 'Media', arguments);
this.id = utils.createUUID();
mediaObjects[this.id] = this;
this.src = src;
this.successCallback = successCallback;
this.errorCallback = errorCallback;
this.statusCallback = statusCallback;
this._duration = -1;
this._position = -1;
exec(null, this.errorCallback, "Media", "create", [this.id, this.src]);
};

// Media messages
Media.MEDIA_STATE = 1;
Media.MEDIA_DURATION = 2;
Media.MEDIA_POSITION = 3;
Media.MEDIA_ERROR = 9;

// Media states
Media.MEDIA_NONE = 0;
Media.MEDIA_STARTING = 1;
Media.MEDIA_RUNNING = 2;
Media.MEDIA_PAUSED = 3;
Media.MEDIA_STOPPED = 4;
Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"];

// "static" function to return existing objs.
Media.get = function(id) {
return mediaObjects[id];
};

/**
* Start or resume playing audio file.
*/
Media.prototype.play = function(options) {
exec(null, null, "Media", "startPlayingAudio", [this.id, this.src, options]);
};

/**
* Stop playing audio file.
*/
Media.prototype.stop = function() {
var me = this;
exec(function() {
me._position = 0;
}, this.errorCallback, "Media", "stopPlayingAudio", [this.id]);
};

/**
* Seek or jump to a new time in the track..
*/
Media.prototype.seekTo = function(milliseconds) {
var me = this;
exec(function(p) {
me._position = p;
}, this.errorCallback, "Media", "seekToAudio", [this.id, milliseconds]);
};

/**
* Pause playing audio file.
*/
Media.prototype.pause = function() {
exec(null, this.errorCallback, "Media", "pausePlayingAudio", [this.id]);
};

/**
* Get duration of an audio file.
* The duration is only set for audio that is playing, paused or stopped.
*
* @return duration or -1 if not known.
*/
Media.prototype.getDuration = function() {
return this._duration;
};

/**
* Get position of audio.
*/
Media.prototype.getCurrentPosition = function(success, fail) {
var me = this;
exec(function(p) {
me._position = p;
success(p);
}, fail, "Media", "getCurrentPositionAudio", [this.id]);
};

/**
* Start recording audio file.
*/
Media.prototype.startRecord = function() {
exec(null, this.errorCallback, "Media", "startRecordingAudio", [this.id, this.src]);
};

/**
* Stop recording audio file.
*/
Media.prototype.stopRecord = function() {
exec(null, this.errorCallback, "Media", "stopRecordingAudio", [this.id]);
};

/**
* Release the resources.
*/
Media.prototype.release = function() {
exec(null, this.errorCallback, "Media", "release", [this.id]);
};

/**
* Adjust the volume.
*/
Media.prototype.setVolume = function(volume) {
exec(null, null, "Media", "setVolume", [this.id, volume]);
};

/**
* Audio has status update.
* PRIVATE
*
* @param id The media object id (string)
* @param msgType The 'type' of update this is
* @param value Use of value is determined by the msgType
*/
Media.onStatus = function(id, msgType, value) {

var media = mediaObjects[id];

if(media) {
switch(msgType) {
case Media.MEDIA_STATE :
media.statusCallback && media.statusCallback(value);
if(value == Media.MEDIA_STOPPED) {
media.successCallback && media.successCallback();
}
break;
case Media.MEDIA_DURATION :
media._duration = value;
break;
case Media.MEDIA_ERROR :
media.errorCallback && media.errorCallback(value);
break;
case Media.MEDIA_POSITION :
media._position = Number(value);
break;
default :
console.error && console.error("Unhandled Media.onStatus :: " + msgType);
break;
}
}
else {
console.error && console.error("Received Media.onStatus callback for unknown media :: " + id);
}

};

module.exports = Media;

});
@@ -0,0 +1,57 @@
cordova.define("org.apache.cordova.media.MediaError", function(require, exports, module) { /*
*
* 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.
*
*/

/**
* This class contains information about any Media errors.
*/
/*
According to :: http://dev.w3.org/html5/spec-author-view/video.html#mediaerror
We should never be creating these objects, we should just implement the interface
which has 1 property for an instance, 'code'
instead of doing :
errorCallbackFunction( new MediaError(3,'msg') );
we should simply use a literal :
errorCallbackFunction( {'code':3} );
*/

var _MediaError = window.MediaError;


if(!_MediaError) {
window.MediaError = _MediaError = function(code, msg) {
this.code = (typeof code != 'undefined') ? code : null;
this.message = msg || ""; // message is NON-standard! do not use!
};
}

_MediaError.MEDIA_ERR_NONE_ACTIVE = _MediaError.MEDIA_ERR_NONE_ACTIVE || 0;
_MediaError.MEDIA_ERR_ABORTED = _MediaError.MEDIA_ERR_ABORTED || 1;
_MediaError.MEDIA_ERR_NETWORK = _MediaError.MEDIA_ERR_NETWORK || 2;
_MediaError.MEDIA_ERR_DECODE = _MediaError.MEDIA_ERR_DECODE || 3;
_MediaError.MEDIA_ERR_NONE_SUPPORTED = _MediaError.MEDIA_ERR_NONE_SUPPORTED || 4;
// TODO: MediaError.MEDIA_ERR_NONE_SUPPORTED is legacy, the W3 spec now defines it as below.
// as defined by http://dev.w3.org/html5/spec-author-view/video.html#error-codes
_MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = _MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED || 4;

module.exports = _MediaError;

});
6 changes: 6 additions & 0 deletions Mobile/platforms/ios/Pitching.xcodeproj/project.pbxproj
Expand Up @@ -49,6 +49,7 @@
D4A0D8761607E02300AEF8BB /* Default-568h@2x~iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = D4A0D8751607E02300AEF8BB /* Default-568h@2x~iphone.png */; };
D57D1EC11CAC45D3B7714FEA /* CDVNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F63DA9BC7424E01938AC80C /* CDVNotification.m */; };
D581DC6A958341A69F98448E /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 507F2F98A3DC452986EC1572 /* AudioToolbox.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
F9F5B2D0226B4365843BC6C5 /* CDVSound.m in Sources */ = {isa = PBXBuildFile; fileRef = B4EFD945C99247F3B433F791 /* CDVSound.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -121,7 +122,9 @@
8FC38F018F58463993289B02 /* CDVVibration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVVibration.h; path = org.apache.cordova.vibration/CDVVibration.h; sourceTree = "<group>"; };
900710A7FDA04B88A7EF69E7 /* CDVDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVDevice.h; path = org.apache.cordova.device/CDVDevice.h; sourceTree = "<group>"; };
9D83BD41A2244D4FB5AC300C /* CDVJokUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVJokUtils.m; path = com.phonegap.plugins.jokutils/CDVJokUtils.m; sourceTree = "<group>"; };
B4EFD945C99247F3B433F791 /* CDVSound.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVSound.m; path = org.apache.cordova.media/CDVSound.m; sourceTree = "<group>"; };
D4A0D8751607E02300AEF8BB /* Default-568h@2x~iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x~iphone.png"; sourceTree = "<group>"; };
E22BF64466FE4BBBB978770E /* CDVSound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVSound.h; path = org.apache.cordova.media/CDVSound.h; sourceTree = "<group>"; };
EB87FDF21871DA7A0020F90C /* merges */ = {isa = PBXFileReference; lastKnownFileType = folder; name = merges; path = ../../merges; sourceTree = "<group>"; };
EB87FDF31871DA8E0020F90C /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; name = www; path = ../../www; sourceTree = "<group>"; };
EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = "<group>"; };
Expand Down Expand Up @@ -266,6 +269,8 @@
8FC38F018F58463993289B02 /* CDVVibration.h */,
9D83BD41A2244D4FB5AC300C /* CDVJokUtils.m */,
EFB57FDA910F479398941482 /* CDVJokUtils.h */,
B4EFD945C99247F3B433F791 /* CDVSound.m */,
E22BF64466FE4BBBB978770E /* CDVSound.h */,
);
name = Plugins;
path = Pitching/Plugins;
Expand Down Expand Up @@ -467,6 +472,7 @@
01AF4C42EC354FE496ED9AD8 /* CDVInAppBrowser.m in Sources */,
755383D60B9547579784DE90 /* CDVVibration.m in Sources */,
8B4D213D204A4827944A6025 /* CDVJokUtils.m in Sources */,
F9F5B2D0226B4365843BC6C5 /* CDVSound.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions Mobile/platforms/ios/Pitching/Pitching-Info.plist
Expand Up @@ -32,8 +32,6 @@
<true/>
<key>NSMainNibFile</key>
<string></string>
<key>NSMainNibFile~ipad</key>
<string></string>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
Expand Down

0 comments on commit b0b47d8

Please sign in to comment.