PDA

View Full Version : Code for mini mp3player, kindly help to make it run locally.


Imoracle
02-01-2008, 01:43 PM
Hello All,

Here below I have pasted a very simple code, while reads an xml file which contains title and location of a song. It reads the file and display the titles in a window. On clicking it, it display the file location in another window and also plays that particualar mp3 song.

All this works fine when I run it from server, i.e. url = "http://127.0.0.1:8080/lps-4.0.7/Workspace/miniplayer.lzx", and mp3 locations like "http://127.0.0.1:8080/lps-4.0.7/Workspace/mp3/song.mp3"

However my requirement is to make it run by client on his computer . i.e. with a url = "file:///C:/miniplayer.lzx.html" and he being able to listen to a file having location = "file:///C:/mp3/song.mp3".

I am trying to achieve this but somehow I am unable to do it.

Please help me here. Below are my codes:

miniplayer.lzx

<canvas>
<class name="vscroller" clip="true" defaultplacement="scrolltarget">
<view name="scrolltarget" width="${immediateparent.width - parent.vsb.width}"/>
<vscrollbar name="vsb"/>
</class>

<dataset src="http:playlist.xml" name="userplaylist" request="true"/>

<window name="main" title="Song List" height="150" width="300" resizable="true">
<view>
<vscroller height="${main.height-45}" width="${main.width-20}">
<text>
<datapath xpath="userplaylist:/playlist/trackList/track/@title" replication="lazy"/>
<handler name="onclick">
audioplayer.loadAudio(this.datapath.getNodeAttribu te('location'));
location.datapath.setFromPointer(this.datapath);
</handler>
</text>
</vscroller>
</view>
<view id="audioplayer" visible="false" play="false">
<method name="loadAudio" args="audio">
Debug.write("Now Playing: " + audio);
this.stop();
this.setSource(audio);
</method>
<handler name="onload">
this.play();
LzAudio.setVolume(100);
</handler>
</view>
</window>
<window name="location" title="$path{'@title'}" height="100" width="600" resizable="true" x="${main.x + main.width}">
<datapath/>
<text datapath="@location"/>
</window>
</canvas>


Kindly can someone from you try to compile it and then try running the swf locally. Please someone help me in this.

PS: format of my playlist is something like this:

playlist.xml

<playlist>
<trackList>
<track title="Poets of the Fall - Carnival of Rust" location="C:\Users\somu\Desktop\JHANTU\Audios\01 - Kailash Kher (Kailasa) - Teri Deewani.mp3"/>
<track title="Poets Of The Fall - Carnival Of Rust1" location="C:\Users\somu\Desktop\JHANTU\Audios\01 - Kailash Kher (Kailasa) - Teri Deewani.mp3"/>
</trackList>
</playlist>


Basically I want my client to be able to play any of his local song hard disk on this miniplayer.

Imoracle
02-01-2008, 02:18 PM
Well I changed the path of mp3 files from C:\... to C:/... and it seems to be loading the song. But un-neceesarily I am still getting this error saying that :

C:/...../...swf is trying to communicate with internet enabled location C:/..../.....html .

Any suggestions on how can I supress this warning.

senshi
02-02-2008, 01:32 AM
If you want to have a local SWF-file which can load local files and communicate with the internet, it must be trusted, see Flash Player 9 Security Paper (http://www.adobe.com/devnet/flashplayer/articles/flash_player_9_security.pdf).

Imoracle
02-02-2008, 02:09 AM
Thanx Senshi,

But I am not trying to connect over to internet using my swf file.

The swf file is on client computer and the songs are on his computer. Then how come internet comes in between.

If you have a look at the open source jw player build using flash action scripting, it is capable of doing the same without any warning.

I guess there is some small mistake which I am committing which doesn't even allow the swf file to play a local file also. Can't understand as to why is it referring a local mp3 file as a file over internet.

senshi
02-02-2008, 10:44 AM
I think I've understood what your actual problem is:
You open the OpenLaszlo-Application through the wrapper html-page and then you get this flash-warning.
This is because the OL-App always communicates with the wrapper html-page, for example create an empty application, deploy it as SOLO and start it through the wrapper html-page -> flash warning appears.
This default communication is made, so the html-page knows when the OL-swf is ready to receive messages, i.e. when you need to communication html <-> swf.
You shouldn't get the warning when you load directly the swf into your browser.

You can also check the current sandbox through:

System.security.sandboxType;

Imoracle
02-02-2008, 10:55 AM
Yes Senshi you git it absolutely right. I don't get a warning if I open the .swf fie directly into th browser.

But actually for my application to complete I need to embed swf on left side of the page and have something else on the right hand side.

Now its quite annoying that open laszlo will give a warning no matter what I do. Because I don't want my clients to be foxed by this warniing. Not many will read through and on seeing the warning they might thing thr is smthing fishy going around.

Is there any work around for this. Can I do something for this ??

Can I in some way supress the warning ??

Also what do you mean by check the current sandbox through, is there any method to suppress this warning ??

senshi
02-02-2008, 11:21 AM
But actually for my application to complete I need to embed swf on left side of the page and have something else on the right hand side.
[...]
Is there any work around for this. Can I do something for this ??
I've taken a look at the wrapper html-page, I think if you change the way how the application is embedded into the html-page, you shouldn't get this warning anymore. For example try to use "SWFObject (http://blog.deconcept.com/swfobject/)" instead of the standard laszlo embed-function. (Also search for SWFObject in this forum, there are a couple of threads about it.)

Also what do you mean by check the current sandbox through, is there any method to suppress this warning ??
No, that was meant just as a tip how you can determine the current sandbox-type, it should be "localWithFile" for your application.

Imoracle
02-02-2008, 12:18 PM
Hi Senshi,

Thanx for your comments but thr still seems to be some problem. I am unable to run that still without a warning.

Here is my html code:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="swfobject.js">
</script>
</head>
<body>
<div id="flashcontent">
<strong>You need to upgrade your Flash Player</strong>
</div>

<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("mediaplayerlocal.swf", "imoracle", "300", "600", "7", "#FFFFFF");
so.write("flashcontent");
// ]]>
</script>
</body>
</html>


I have attached the mediaplayerlocal.swf along, and also the swfobject.js i am using.

Kindly rename them to swfobject.js and mediaplayerlocal.swf.

I also checked my security settings, and its LocalWithFile.

Any further suggestions ??

senshi
02-02-2008, 12:40 PM
Ok, in this case, I'd suggest to open a JIRA-bug (http://jira.openlaszlo.org) and you could send a mail to the laszlo-user mailinglist, maybe there's someone who can help you or who has experienced the same problems as you have. Apparently, there are also a couple of code-changes within the platform necessary to avoid this message.

d~l
02-03-2008, 11:07 AM
Have you given your lzx code an id .. which swfobject needs ..

<canvas id="mymoviename">

var so = new SWFObject("mediaplayerlocal.swf", "mymoviename", "300", "600", "7", "#FFFFFF");

or if there is no id attribute set, the default id is "lzxapp"

<canvas>

var so = new SWFObject("mediaplayerlocal.swf", "lzapp", "300", "600", "7", "#FFFFFF");

Imoracle
02-03-2008, 11:19 AM
oh u mean the id which i give in html file must also be given in the lzx file, is it....??

d~l
02-03-2008, 11:55 AM
Yes .. you must specify the target id and name of your openlaszlo compiled swfobject ..

easiest way is to compile using <canvas id="yourmovieid" .. (which if missing is set as "lzapp") ..

Imoracle
02-04-2008, 10:55 AM
Hello d~l,

I tried the following things:

swf2js.lzx

<canvas id="somu">
<button>Hello</button>
</canvas>


compile it with swf8. Took the swf2js.swf file and embedded it in test.html file as follows:

test.html

<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body bgcolor="#FFFFFF">
<div id="flashcontent"></div>
<script type="text/javascript">
var so = new SWFObject("swf2js.swf", "somu", "300", "600", "7", "#FFFFFF");
so.write("flashcontent");
</script>
</body>
</html>


Then i try to load this test.html file locally, i.e. with url :

file:///C:/Documents and Settings/Desktop/test.html

and I get a warning reading: "swf2js.swf file is trying to communicate with an internet enabled page test.html"

Any idea what should I do next ??

d~l
02-06-2008, 06:49 AM
A few points to understand ..

you should compile your flash object with proxied="false" attribute set

<canvas id="somu" proxied="false">
<button>Hello</button>
</canvas>

then, depending on what version of openlaszlo you are using, you will see in the same folder as swf2js.lzx

this compiled file ..
swf2js.lzx.lzr=swf7.swf


so you must change your "var so" to target the compiled flash object name and file extension ..


var so = new SWFObject("swf2js.lzx.lzr=swf7.swf", "somu", "300", "600", "7", "#FFFFFF");

You can also shorten the compiled file extension name to swf2js.swf

...

If you must click on the local test.html file to launch the mediaplayer instead of serving from a web site

you will have a long, clumsy, local file address like this (I'm testing using openlaszlo-4.0.7).

file:///c:/apache-tomcat-5.5.20/webapps/openlaszlo-4.0.7/my-apps/forumtests/mediaplayer/test.html

Your browser will object to opening a local file .. but it does launch if in options you give permission

This is a very messy way to launch your player so either place your test.html in a remote web site to be accessed, or, if it must be run without internet access, consider embedding your flash object and html code into an executable wrapper:- screenweaver (http://screenweaver.org/doku.php) which installs haXe and Neko.

Imoracle
02-06-2008, 11:30 PM
Thanx d~l for your valuable suggestions,
However once again I failed in running my swf successfully without a warning from the browser.

Here is my laszlo code:

playlocal.lzx

<canvas id="somu" proxied="false">
<button>Hello</button>
</canvas>


Here is my html code:

playlocal.html

<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="flashcontent">
This text is replaced by the Flash movie.
</div>
<script type="text/javascript">
var so = new SWFObject("playlocal.lzx.lzr=swf7.swf", "somu", "300", "600", "7", "#FFFFFF");
so.write("flashcontent");
</script>
</body>
</html>


Indeed when I opened the HTML file locally it have a clumsy URL, in my case it reads like:
file:///C:/Program%20Files/OpenLaszlo%20Server%204.0.7/Server/lps-4.0.7/Workspace/OldArchive/IO/playlocal.html

but I am OK with that. However I don't want to have the warning :


"Flash player has stopped a potential unsafe operation. A file playlocal.swf is trying to interact with a internet enabled playlocal.html"

Also I dont want my swf to be converted to an exe or something else. I know of an existing player (the famous JW Player) which I have been able to embed and play locally successfully without a warning.

Hence I guess its not a flash restriction, just that we are unable to figure out the correct configurations in laszlo to do that.

If there is still another opton please let me know. I will try out everything till the end. ;)

d~l
02-07-2008, 01:42 AM
Try compiling as Flash 8 instead of Flash 7 ..

you will then see this .. swf2js.lzx.lzr=swf8.swf

and change ..

var so = new SWFObject("swf2js.lzx.lzr=swf8.swf", "somu", "300", "600", "8", "#FFFFFF");

or just shorten name .. "swf2js.lzx.lzr=swf8.swf" .. to .. "swf2js.swf"

also read here ...

global security settings (http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html)

greghuddleston
02-11-2008, 09:01 PM
Bump.

Have you found a solution to this issue?

I am about to go down the same path (local MP3 file playing thru OL)

TIA GHudd

Imoracle
02-11-2008, 10:46 PM
No man I have tried almost every possible thing from my side, what people suggested, but I am still getting that security warning...

Dont know what to do, whom to approach....If you find a solution do lemme know

d~l
02-12-2008, 02:02 AM
??

test.html seems to launch ok for me in browser .. Firefox 2.0.0.12

file:///c:/apache-tomcat-5.5.20/webapps/openlaszlo-4.0.7/my-apps/forumtests/mediaplayer/test.html

swf2js.lzx ...


<canvas id="somu" proxied="false">
<button>Hello</button>
</canvas>


note: compiled as Flash 8 .. proxied="false" .. into swf2js.lzx.lzr=swf8.swf

note: reference to "8" in SWFObject args ..

test.html


<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body bgcolor="#FFFFFF">
<div id="flashcontent"></div>
<script type="text/javascript">
var so = new SWFObject("swf2js.lzx.lzr=swf8.swf", "somu", "300", "600", "8", "#FFFFFF");
so.write("flashcontent");
</script>
</body>
</html>



postscript ...

but it does not work in IE browser as you say !

If it must run in IE perhaps try LaunchinIE Active X Control (http://www.whirlywiryweb.com/q%2Flaunchinie.asp)

Imoracle
02-12-2008, 03:09 AM
Thanks a lot d~l , I am in office, will surely try it out this evening and let you know what happened

d~l
02-12-2008, 11:09 AM
If you don't like having to instal an ActiveX Control .. here are few earlier threads I forgot about .. some time since I've been back to the forum ..

announcing the new tag for dhtml (http://weblog.openlaszlo.org/archives/2007/01/announcing-the-new-tag-for-dhtml/)

note reference to proxy in the above thread ..

embedded html (http://forum.openlaszlo.org/showthread.php?t=7251)

and search for "deng" threads in forum. Deng component allows xhtml content inside flash object (instead of having an iframe on the right).

Imoracle
02-13-2008, 06:28 AM
Thanx d~l, It worked out perfectly for me.

Now if you can make me help this achieve I will be more than happy.

I just want to call a javascript function, on the click of the button.


<canvas id="somu" proxied="false">
<button>Hello
<handler name="onclick">
LzBrowser.loadJS("javascript:test('Hi')");
</handler>
</button>
</canvas>


Though this code works for me when I load the page through server, however when I load the page locally, i.e. with URL

file:///C:/Program%20Files/OpenLaszlo%20Server%204.0.7/Server/lps-4.0.7/Workspace/MediaplayerV2.0/mediaplayer.html

I don't get any alert message.

My mediaplayer.html is like this:

<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function test(mssg) {
alert(mssg);
}
</script>
</head>
<body>
<div id="flashcontent">
This text is replaced by the Flash movie.
</div>
<script type="text/javascript">
var so = new SWFObject("localbutton.lzx.lzr=swf8.swf", "somu", "300", "600", "8", "#FFFFFF");
so.write("flashcontent");
</script>
</body>
</html>


Comments and reply most awaited.

Thanx,
Imoracle