I am attempting to retrieve metadata from a URLResource. The URLResource is not controlled by me, but passed into a function that I am using.
The URLResource is created like this:
var resource:URLResource = new URLResource("http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv");
// Add Metadata for the URLResource
var VideoParams:Object = {
Name:"Logo Video",
Owner:"Self",
Duration:"1:25:20",
category:"education"
}
resource.addMetadataValue("VideoParams", VideoParams);
var media:MediaElement = factory.createMediaElement(resource);
Now the URLResource contains the metadata. I will recieve a MediaElement resource. How do I extract the metadata back?
Here's what the debugger shows (media is a MediaElement object containing the URLResource w/ metadata) :
fdb>print media.resource.
$1 = [Object 246396705, class='org.osmf.media::URLResource']
_mediaType = null
_metadata = [Object 416970209, class='flash.utils::Dictionary']
_mimeType = null
url = "http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv"
fdb>print media.resource._metadata.
$2 = metadata = [Object 416970209, class='flash.utils::Dictionary']
VideoParams = [Object 416970305, class='Object']
(fdb)print media.resource._metadata.VideoParams.
$3 = VideoParams = [Object 416970305, class='Object']
category = "education"
Duration = "1:25:20"
Owner = "Self"
Name = "Logo Video"
I've attempted extracting the metadata object with:
media.resource.getMetadata("VideoParams");
and a host of other attempts, but can't figure out how to get at that darned metadata.
Any thoughts greatly appreciated!
This actually turned out to be pretty easy...just needed to use the getMetadataValue function in the URLResource object like this:
var temp:Object = media.resource.getMetadataValue("VideoParams");
trace('Owner:', temp.Owner);
Related
Struggling to find any documentation to do a simple GET request to a URL to return JSON in Actionscript / Flex.
Anyone know
Use the URLLoader API.
var myJSON :Object; //listing as per "key:" with "value"
var str_JSON: String = ""; //if you need text String not data Object
var siteloader :URLLoader = new URLLoader( new URLRequest( your_URL ) );
siteloader.addEventListener(Event.COMPLETE, whenSiteLoaded);
function whenSiteLoaded( evt :Event ) :void
{
myJSON = JSON.parse(evt.target.data); //get into Object
str_JSON = evt.target.data; //get into String
//... any other code
}
You should add to the above the listeners for error conditions (eg: a "file not found" situation)
Hi I am integrating an internal offline localized leaderboard for a game I have created.
Getting a bit lost using Array & Shared Object.
I thought this would work but when I trace values they return as [object Object]
the code wrote is:
import flash.net.SharedObject;
var HScores:SharedObject = SharedObject.getLocal("HighScoresValues");
// ASSIGN Text Fields to Vars
var USR_Level_Reached = LevelTXT.text;
var USR_Name = PlayerTXT.text;
// array
var highScores:Array = new Array();
if(HScores.data.d_SCORES==undefined)
{
HScores.data.d_SCORES = highScores;
} else {highScores.push({score:int(0) , player:"No Name"}); }
if(HScores.data.d_SCORES)
{
highScores = HScores.data.d_SCORES;
}
Button1.addEventListener(MouseEvent.CLICK, Button1_MouseClickEvent);
function Button1_MouseClickEvent(event:MouseEvent)
{
USR_Level_Reached = LevelTXT.text;
USR_Name = PlayerTXT.text;
highScores.push({score:int(USR_Level_Reached) , player:String(USR_Name)});
highScores.sortOn("score", Array.DESCENDING | Array.NUMERIC);
HScores.data.d_SCORES = highScores;
HScores.flush();
trace("Shared Data = "+HScores.data.d_SCORES);
trace("Array Data = "+highScores);
}
Not sure were am I going wrong,
but its not passing new text fields to my Array on button press,
though the array seems to be adding blank values to its self
& also passing its blank values to SharedObjects correctly
but traces as [object Object], [object Object], [object Object] ?
any ideas?
I have the following code:
thinkGearSocket = new Socket();
var configuration : Object = new Object();
configuration["enableRawOutput"] = true;
configuration["format"] = "Json";
thinkGearSocket.connect("127.0.0.1", 13854);
thinkGearSocket.addEventListener(ProgressEvent.SOCKET_DATA, dataHandler);
thinkGearSocket.writeUTFBytes(JSON.encode(configuration));
It works for flash player 10 but for flash player 11 I get an error saying:
1061: Call to a possibly undefined method encode though a reference with static type flash.net:socket
I had the same error for the decoding with this:
private function dataHandler(e : ProgressEvent){
//read data from the socket
var packetString : String = thinkGearSocket.readUTFBytes(thinkGearSocket.bytesAvailable);
thinkGearSocket.flush();
//split the data into an array
var packets : Array = packetString.split(/\r/);
var data:Object;
//iterate through array elements
for each (var packet:String in packets){
//sometimes the packet is empty
if(packet != "") {
try {
data = JSON.decode(packet);
//trace(packet);
} catch ( jError: JSONParseError) {
// do exception handling here
label1.text = jError.text;
}
But I changed:
data = JSON.decode(packet);
to:
data = JSON.parse(packet);
and now I don't get an error for that part. how do I fix the encoding part for Flash player 11 and AIR 3.0?
You need to use the stringify method instead of encode for Flash 11 or greater.
stringify(value:Object, replacer:* = null, space:* = null):String
You can see more information in the AS3 livedocs for stringify.
In Unityscript I'm able to directly access audio data. In the scene, I have a gameobject with a sound file and a script attached to it.
var mySound : AudioClip;
mySound = audio.clip;
var mySoundChannels = mySound.channels;
However, I'm having problems trying to access audio data via a function:
#pragma strict
var mySound : AudioClip;
function Start()
{
mySound = audio.clip;
GetAudio(mySound);
}
function GetAudio(au)
{
print ("Audio: " + (mySound === au)); // true
//var mySoundChannels = mySound.channels; // works
var mySoundChannels = au.channels; // fails
var stereoOrNot = (mySound.channels == 2 ? "stereo" : " mono"); //works
print(stereoOrNot);
}
I thought I could access au.channels, but I'm not sure where I'm going wrong I (apart from wanting to access audio indirectly)
Since you are using a dynamic variable there, I'm not sure if the var mySoundChannels will be typed to an AudioClip or an int. If it is an AudioClip then it will fail because channels are read only. Try it with int mySoundChannels = au.channels;
I am trying to make my chrome sender application send metadata to the default media receiver application but the default media receiver does not show the metadata. I cannot find documentation or examples. Does anybody know how implement this? Below code plays the audio but the player does not show any image or other metadata.
Initialization:
var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID);
var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
sessionListener,
receiverListener);
chrome.cast.initialize(apiConfig, onInitSuccess, onError);
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
...
Loading media
url = "url-to-media"
var mediaInfo = new chrome.cast.media.MediaInfo(url, 'audio/aac');
mediaInfo.metadata = new chrome.cast.media.MusicTrackMediaMetadata()
mediaInfo.metadata.albumName = 'This is the name of the album'
mediaInfo.metadata.artistName = 'This is the name of the artist'
mediaInfo.metadata.songName = 'This is the name of the song'
im = chrome.cast.Image('http://m1.behance.net/rendition/modules/575407/disp/822271229466847.png')
mediaInfo.metadata.images = new Array(im)
var request = new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request,onMediaDiscovered.bind(this, 'loadMedia'), onMediaError())
Try this -
mediaInfo.metadata.title = 'This is the name of the song';
mediaInfo.metadata.subtitle = 'This is the name of the artist';
We've just released a Cast extension Beta that has fixed this issue. See this announcement: https://plus.google.com/+ShawnShen/posts/aVXSHyceNbR.
I also added a project on github that provides sample code at:
https://github.com/googlecast/CastMedia-chrome
Currently the default media receiver app accepts certain metadata fields. Detailed specs are given here: https://developers.google.com/cast/docs/reference/messages.
For the MusicTrackMediaMetaData type, be sure to set metadataType to 3. The following snippet works.
mediaInfo.metadata = new chrome.cast.media.MusicTrackMediaMetadata()
mediaInfo.metadata.metadataType = 3;
mediaInfo.metadata.title = 'This is the name of the title';
mediaInfo.metadata.albumArtist = 'This is the name of the album artist';
mediaInfo.metadata.artist = 'This is the name of the artist';
mediaInfo.metadata.albumName = 'This is the name of the album';
//mediaInfo.metadata.composer = 'composer';
//mediaInfo.metadata.trackNumber = 13;
//mediaInfo.metadata.discNumber = 2;
mediaInfo.metadata.releaseDate = '2011';
mediaInfo.metadata.images = [{'url': 'http://m1.behance.net/rendition/modules/575407/disp/822271229466847.png'}];
var request = new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError());
A bug has been filed to fix some mismatch between Chrome Sender SDK and default receiver app.
You can always do your own custom receiver app and add your own custom data like the following.
var mediaInfo = new chrome.cast.media.MediaInfo(url, 'audio/mp3');
var request = new chrome.cast.media.LoadRequest(mediaInfo);
var payload = {
"albumName": 'This is the name of the album',
"songName": 'This is the name of the song',
"thumb": 'http://m1.behance.net/rendition/modules/575407/disp/822271229466847.png',
"artistName": 'This is the name of the artist'
};
var json = {
"payload": payload
};
request.customData = json;