I am looking for a way to decode part of my Object array with the jQuery base64 decoder for the jPlayer using the ttwMusicPlayer.
The array:
var myPlaylist = [
{
mp3: 'aHR0cDovL2xvY2FsaG9zdC90aGVtZWxpdC9yb2NrbnJvbGxhL2ZpbGVzLzIwMTEvMTAvMDEtQnJpZGdlLUJ1cm5pbmcubXAz',
title: 'Bridge Burning',
artist: 'Rock N' Rolla',
cover: 'http://localhost/themelit/rocknrolla/files/2011/10/folder-300x300.jpg',
},{
mp3: 'aHR0cDovL2xvY2FsaG9zdC90aGVtZWxpdC9yb2NrbnJvbGxhL2ZpbGVzLzIwMTEvMTAvMDItUm9wZS5tcDM=',
title: 'Rope',
artist: 'Rock N' Rolla',
cover: 'http://localhost/themelit/rocknrolla/files/2011/10/folder-300x300.jpg',
},
];
The player:
$j('#audio-player').ttwMusicPlayer(myPlaylist, {
autoPlay: false,
description: albumdesc,
jPlayer: {
swfPath: swfpath,
solution: 'html, flash',
supplied: 'mp3',
}
});
Thinking of creating a function to parse out myPlaylist like:
function maybe_decode(theObject) {
$j.each(theObject, function(value, key){
//console.log( $j.base64Decode(key.mp3) );
if( key.mp3 )
return $j.base64Decode( key.mp3 );
else
return key;
});
}
Not working exactly, need to keep the array but decode the mp3 key value.
Thoughts?
UPDATE:
Kind of got it working with this inside maybe_decode()
var Values = [];
$j.each(theObject, function(idx, obj) {
$j.each(obj, function(key, value) {
if( key == 'mp3' )
value = $j.base64Decode( value );
Values.push(key + ": " + value);
//console.log(key + ": " + value);
});
});
console.log(Values);
return Values;
The only problem is that it dumps the array of multiple indexes (in this case 2) into one array. Trying to push it back into the correct array format...
1 Answer 1
If I'm reading your code right ... your Values
array will end up holding strings when you're done. What you should probably be doing is along the lines of this:
var Values = [];
$j.each(theObject, function(idx, obj) {
var newVals = {};
$j.each(obj, function(key, value) {
if( key == 'mp3' )
value = $j.base64Decode( value );
newVals[key] = value;
});
Values.push(newVals);
});
console.log(Values);
return Values;
This creates an object, using your initial structure, and populates it with the necessary information. Then it pushes the object into the Values
array, which should end up being in the same format as your original array ...