// Define the error callback for all the asynchronous calls
function onError(response) {
console.log( "The following error occurred: " + response.name);
}
// got the folder list as asynchronous calls
function DirectoryArray(directories) {
console.log("Found directories " + ", directories.length: " + directories.length);
for (var i = 0; i < directories.length; i++) {
console.log(i + ":" + " title: " + Directories[i].title);
console.log("path : " + Directories[i].folderURI);
}
}
// Get a local media source.
var manager = Tizen.Content;
// Let's try to retrieve the folder list.
manager.getDirectories(DirectoryArray,onError);
// Define the error callback for all the asynchronous calls
function onError(response) {
console.log( "The following error occurred: " + response.name);
}
//List of audio items on the phone.
function mediaItemArray (contents) {
console.log("Successfully retrieved the list of Audio items");
for (var i=0; i < contents.length; i++) {
console.log(i + ":" + contents[i].type + ":" + contents[i].title + ":" +contents[i].mimeType);
console.log("album:" + contents[i].album);
console.log("artists:" + contents[i].artists[0]);
console.log("duration:" + contents[i].duration);
console.log("playedTime :" + contents[i].playedTime);
console.log("playCount :" + contents[i].playCount);
console.log("Item copyright: " + contents[i].copyright);
console.log("Item bitrate: " + contents[i].bitrate);
console.log("Item trackNumber: " + contents[i].trackNumber);
console.log("Item size: " + contents[i].size);
}
}
// Retrieve the ContentManager interface instance using the tizen global object
var manager = tizen.content;
// Let's try to retrieve the Audio list.
var contentType = "AUDIO";
var filter = new Tizen.AttributeFilter("type", "EXACTLY", ContentType);
console.log("Getting the list of audio files on the phone");
manager.find(MediaItemArray, onError, null, filter);
// function called on successful launch of music player application
function onsuccess() {
console.log("The application has launched successfully");
}
tizen.application.launch("org.tizen.music-player", onsuccess);
//Create an ApplicationControl object and define the desired functionality required from the application to be launched. The application needs to have an operation type suitable for selecting files, with URI as null, and the MIME type as "audio/*" .
var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/view", null, "audio/*");
//Define the format of the reply you want to receive from the application control
var appControlReplyCB =
{
// Reply is sent if the requested operation is successfully delivered
onsuccess: function(reply)
{
for (var num = 0; num < reply.data.length; num++)
{
console.log("reply.data["+num+"].key = "+ reply.data[num].key);
console.log("reply.data["+num+"].value = "+ reply.data[num].value);
}
}
}
// Call the launchAppControl() method to find a suitable application to select the audio files
tizen.application.launchAppControl(appControl, null,
function(){console.log("launch appControl succeeded");},
function(e){console.log("launch appControl failed. Reason: " + e.name);},
appControlReplyCB);
// Define the error callback for all the asynchronous calls
function onError(response) {
console.log( "The following error occurred: " + response.name);
}
//List of videos in the phone.
function mediaItems (media) {
console.log("Successfully retrieved the list of videos");
for(var i in media) {
console.log(i + ":" + media[i].type + ":" + media[i].title + ":" +media[i].mimeType);
console.log("geolocatoin-latitude:" + media[i].geolocation.latitude + " longitude:" + media[i].geolocation.longitude);
console.log("album:" + media[i].album);
console.log("artists:" + media[i].artists[0]);
console.log("duration:" + media[i].duration);
console.log("width:" + media[i].width);
console.log("height:" + media[i].height);
console.log("playedTime :" + media[i].playedTime);
console.log("playCount :" + media[i].playCount);
}
}
// Retrieve the ContentManager interface instance using the tizen global object.
var manager = tizen.content;
// Let's try to retrieve the videos list.
var contentType = "VIDEO";
var filter = new Tizen.AttributeFilter("type", "EXACTLY", contentType);
manager.find(MediaItems, onError, null, filter);
var mediaSource;
var index = 0;
var len = 0;
var folderArray = [];
var typeFilter = new Tizen.AttributeFilter("type", "EXACTLY", "VIDEO");
// Define the error callback for all the asynchronous calls
function onError(response) {
console.log( "The following error occurred: " + response.name);
}
//List of videos in the phone.
function MediaItems (media) {
console.log("Successfully retrieved the list of videos");
for(var i in media) {
console.log(i + ":" + media[i].type + ":" + media[i].title + ":" +media[i].mimeType);
console.log("geolocatoin-latitude:" + media[i].geolocation.latitude + " longitude:" + media[i].geolocation.longitude);
console.log("album:" + media[i].album);
console.log("artists:" + media[i].artists[0]);
console.log("duration:" + media[i].duration);
console.log("width:" + media[i].width);
console.log("height:" + media[i].height);
console.log("playedTime :" + media[i].playedTime);
console.log("playCount :" + media[i].playCount);
}
if(index < len) {
console.log("Start getting the list of videos from folder with id: "+ folderArray[index].id);
mediaSource.find(MediaItems, onError, folderArray[index++].id, typeFilter);
}
}
// get the folder list as asynchronous calls
function MediaFolders (folders){
console.log(folders.length + " folder(s) found");
len = folders.length
for (var i = 0; i < len; i++) {
if (folders[i].storageType == "INTERNAL") {
folderArray.push(folders[i]);
console.log(i + ":" + " title: " + folders[i].title);
console.log("id: " + folders[i].id);
console.log("path : " + folders[i].folderURI);
console.log("storageType : " + folders[i].storageType);
console.log("modifiedDate : " + folders[i].modifiedDate);
}
}
console.log(folders.length + " internal folder(s) found");
if(index < len) {
console.log("Start getting the list of videos from folder with id: "+ folderArray[index].id);
mediaSource.find(MediaItems, onError, folderArray[index++].id, typeFilter);
}
}
// Retrieve the ContentManager interface instance using the tizen global object.
mediaSource = = tizen.content;
console.log("Start getting the list of folders in internal memory");
// Let's try to retrieve the folder list.
mediaSource.getDirectories(MediaFolders,onError);
id - 要启动的应用程序的标识符。 如果 ID 为空或未指定,系统将尝试查找要为所请求的应用程序控件
启动的应用程序。 [空]
successCallback - 调用成功结束时要调用的方法。 [可选][空]
errorCallback - 发生错误时要调用的方法。 [可选][空]
replyCallback - 当应用程序从启动的应用程序取回结果时要调用的方法。 [可选][空]
//Create an ApplicationControl object and define the desired functionality required from the application to be launched. The application needs to have an operation type suitable for selecting files, with URI as null, and the MIME type as "video/*" .
var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/view", null, "video/*");
Define the format of the reply you want to receive from the application control:
var appControlReplyCB =
{
// Reply is sent if the requested operation is successfully delivered
onsuccess: function(reply)
{
for (var num = 0; num < reply.data.length; num++)
{
console.log("reply.data["+num+"].key = "+ reply.data[num].key);
console.log("reply.data["+num+"].value = "+ reply.data[num].value);
}
}
}
// Call the launchAppControl() method to find a suitable application to select the video files:
tizen.application.launchAppControl(appControl, null,
function(){console.log("launch appControl succeeded");},
function(e){console.log("launch appControl failed. Reason: " + e.name);},
appControlReplyCB);
var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/create_content", null, "video/*");
var appControlReplyCB = {
// callee now sends a reply
onsuccess: function(reply) {
for (var num = 0; num < reply.data.length; num++) {
console.log("reply.data["+num+"].key = "+ reply.data[num].key);
console.log("reply.data["+num+"].value = "+ reply.data[num].value);
}
},
// Something went wrong
onfail: function() {
console.log('Launch service failed');
}
};
//Launch the service with control
tizen.application.launchAppControl(appControl, null,
function(){console.log("launch appControl succeeded");},
function(e){console.log("launch appControl failed. Reason: " + e.name);},
appControlReplyCB);
注: 开发者设备上的前置摄像头无法访问,因此这个 API 将无法在设备上运作。 可以通过网络摄像头在模拟器上良好运作。
HTML 代码:
Javascript 代码:
function getVideoStream()
{
navigator.webkitGetUserMedia({video : true}, SuccessCallBack, errorCallBack);
}
function SuccessCallBack(stream)
{
var URL = window.webkitURL;
document.getElementById("videoPlay").src = URL.createObjectURL(stream);
}
function errorCallBack(error)
{
alert('No support for webkitGetUserMedia()');
}