Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 10, 2012, 01:45:58 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Join our IRC channel: ##psp-programming on freenode
Home Help Search Shop Login Register
Digg This!
Pages: [1]
Print
Author Topic: Send command javascript without refresh on PSP browser  (Read 3724 times)
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« on: October 24, 2009, 04:00:23 PM »

Hi people.

I hope i'm in the good section for my question.

First, my english and my javascript Knowledge = Not so good.

I use the music player Foobar. One of my dream is to remote Foobar with my PSP, with the wifi connection.

I found that project:
http://www.hydrogenaudio.org/forums/index.php?showtopic=62218

With this plugin, we can remote control foobar with HTTP commands.

That's working good, I can make my template too, perfect. Execpt one thing.

On my PSP internet browser, any time I press a button (play,next,..) this doing the work but the page are refresh completly. It's a little inconvenient cause the browser is not too fast and I want to make my own icons, so the refresh time is too long. Not so long, but too long for me.

So, you can see on the project page, some guys have do many templates with AJAX commands. It's perfect for PC browser or iphone, but not the Netfront PSP browser.

So, I search everywhere on the internet and found two little things:

http://www.psp-programming.com/forums/index.php?PHPSESSID=5trqm7m8j0a6f9h8jel282i3k4&topic=2890.msg24105#msg24105

and
http://forums.qj.net/psp-flash-player-discussions-releases/118086-ajax-psp.html

Interesting, vey intersting. But I don't know enough javascript for make this work myself.

I try all the day, all the things I can but I can"t make this working with my remote plugin.

The second link is the most interesting for me, the proof page working good on my PSP. So I just want to when I press play button, the command send to the server without refresh.

The commands are in FORM GET. Here is the code of the default template with my icons:

HTML:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Mon Index Foobar 2000</title>

<script type="text/javascript" src="script.js"></script> <!--Ligne importe le javascript à partir d'un fichier -->


<link rel="stylesheet" type="text/css" href="style.css" /> <!--Ligne importe le style CSS à partir d'un fichier-->
</head><body onload="mouse_capture_init(); fit();" onresize="fit();">
<form action="/" method="get" name="cmd_form" target="_self" class="frm">


<!--Ces 6 lignes sont les icones-->
<input name="Stop" title="Stop Playback" type="image" src="stop.png"  ;width="50"; height="50"; class="stop" ; onclick="pc(this.name);">
<input name="PlayOrPause" title="Pause/resume playback" type="image" src="pause.png" width="50" ; height="50" ; onclick="pc(this.name);">
<input name="Start" title="Start playback" type="image" src="lecture.png" width="50" ; height="50" ; onclick="pc(this.name);">
<input name="StartPrevious"  title="Play previous track" type="image" src="precedent.png" width="50" ; height="50" ; onclick="pc(this.name);">
<input name="StartNext" title="Play next track" type="image" src="suivant.png" width="50" ; height="50" ; onclick="pc(this.name);">
<input name="StartRandom" title="Play random track" type="image" src="random.png" width="50" ; height="50" ; onclick="pc(this.name);">
<select title="Playback order" onchange="pc('PlaybackOrder',this.value);">[PLAYBACK_ORDER_OPTION]</select><!--Boite de dialogue changer l'ordre de lecture-->
<select title="Volume level" onchange="pc('Volume',this.value);">[VOLUME_OPTION]</select>%<!--Changement de son-->
<p>
<select title="Playlist actions" id="Actions" style="background-color: #eeeeee;" onchange="act=this.selectedIndex;"><option>Start</option><option>Enqueue</option><option>Dequeue</option><option>Focus</option><option>Delete</option></select>
<input name="EmptyPlaylist" title="Empty playlist" type="button" value="&#8212;" onclick="if (confirm('Empty active playlist?')) pc(this.name); else return false;">
<select title="Playlists" onchange="pc('SwitchPlaylist',this.value);">[PLAYLISTS_OPTION]</select>
<a href="/?cmd=Browse">[&nbsp;...&nbsp;]</a>
</p>
<p><input type="text" size="9" style="width: auto" onkeypress="document.cmd_form.cmd.value='SearchMediaLibrary'; document.cmd_form.param1.value=this.value;" value="[SEARCH_REQUEST]">
<input name="QueryRetrace" title="Retrace/init query" type="button" value=" < " onclick="pc(this.name);">
<select title="Media library query" id="QueryAdvance" onchange="pc('QueryAdvance',this.value);">[QUERY_OPTION]</select>&nbsp;[QUERY_INFO]</p>
<br><p id="npstr"><span id="npd" style="white-space: nowrap;" onclick="np_onclick();"><span id="np" class="npc">&nbsp;</span><span id="track_title" class="track">[HELPER1]</span>&nbsp;<span id="t_time" class="track"></span></span>&nbsp;&nbsp;</p>
<p><span id="status"></span>&nbsp;<font size="-2" color="#ababab">[HELPER3]</font></p>
</div>
<input name="cmd" type="hidden" value=""><input name="param1" type="hidden" value="">



<p>[PLAYLIST_PAGES]</p>


<div id="playlist" style="border-top: 1px solid #000000; clear: both; z-index: +1; ">


<table id="pl">
[PLAYLIST]
<tr><td id="totals"></td><td class="playlist_time">[PLAYLIST_TOTAL_TIME]</td><td class="playlist_time">[QUEUE_TOTAL_TIME]</td></tr>
</table>
</div>
<!--[PGT]s-->
</body>
</html>

Javascript:
Code:
var mouseX = 0;
var p_key = 0;
var act = 0;

function KeyPress(e) {
p_key = e;
if (p_key == 16) // shift -- focus
act = 3;
else if (p_key == 17) // ctrl -- remove
act = 4;
else if (p_key == 81) // q -- enqueue
act = 1;
else if (p_key == 87) // w -- dequeue
act = 2;
else
act = 0;
document.getElementById('Actions').selectedIndex = act;
}

function pad(str, chr, count) {
var str_out = str.toString();
while (str_out.length < count)
str_out = chr + str_out;
return str_out;
}

function pc(c, p) {
var com = c || ''; var par = p || '';
with (document.cmd_form)
{
cmd.value = com;
param1.value = par;
submit();
}
}

function format_time(time) {
mins = Math.floor(time / 60);
secs = pad(time % 60, '0', 2);
return mins+":"+secs;
}

function set_t_pos(time) {
var str = format_time(time) + " / ";
document.getElementById("t_time").innerHTML = str + ( [ITEM_PLAYING_LEN] > 0 ? format_time([ITEM_PLAYING_LEN]) : '?' );
}

function set_np_width(t_sec, t_length) {
var np_width = document.getElementById("npd").offsetWidth;
np_width = np_width < 100 ? 100: np_width;
document.getElementById('np').style.width=Math.floor(np_width * t_sec / t_length) + "px";
}

function t_playback_timer(t_sec, t_length) {
if (t_sec <= t_length && t_length != 0)
{
set_t_pos(t_sec);
if (t_length != 0)
set_np_width(t_sec, t_length);
setTimeout('t_playback_timer('+(t_sec+1)+','+t_length+')',1000);
}
}

function a(track) { // do a(ction) on clicked entry
if (act == 0) pc('Start', track);
else if (act == 1) pc('QueueItems', track);
else if (act == 2) pc('DequeueItems', track);
else if (act == 3) pc('MoveCursor', track);
else if (act == 4) pc('Del', track);
}

function np_onclick() {
with (document)
pc('Seek', Math.round((mouseX-getElementById("np").offsetLeft)*100 / (getElementById("npd").offsetWidth)) );
}

function mouse_capture_init() {
if (document.layers? true : false)
captureEvents(Event.MOUSEMOVE)
document.onmousemove = handleMouseMove;
}

function handleMouseMove(evt) {
if (evt)
mouseX=evt.clientX;
else
if (event)
   mouseX=event.x;
return false;
}

function fit() {
with (document.getElementById('playlist'))
{
style.position = 'static'; // important for the onresize event
style.overflowY = 'auto';
style.top = offsetTop + 'px';
style.left = offsetLeft + 'px';
style.right = offsetLeft + 'px';
style.bottom = '8px'; // fit this to your taste
style.position = 'fixed';

var npelem = document.getElementById("nowplaying");
if (npelem)
{
scrolltop = npelem.offsetTop - offsetHeight/2;

if (scrolltop > 0)
scrollTop = scrolltop;
}
}
}

document.onkeydown = function(evt) { KeyPress(evt?evt.keyCode:event.keyCode); }


with (document)
{
act = [LAST_ACTION];
getElementById('Actions').selectedIndex = act;
    var i_p;
    if ('[PLAYLIST_ITEM_PLAYING]' != '?')
      i_p = parseInt('[PLAYLIST_ITEM_PLAYING]') + 1;
    else
      i_p = '?';

if ([IS_PLAYING]) { // start progressbar if playing
t_playback_timer([ITEM_PLAYING_POS],[ITEM_PLAYING_LEN]);

    if ('[AUTO_REFRESH]' != '')
    {
        if (([ITEM_PLAYING_LEN]>0) && ([ITEM_PLAYING_POS] < [ITEM_PLAYING_LEN]) )
            setTimeout('pc()',([ITEM_PLAYING_LEN]-[ITEM_PLAYING_POS])*1000 + 500);
        else
        if (([ITEM_PLAYING_POS] > [ITEM_PLAYING_LEN]) )
            setTimeout('pc("RefreshPlayingInfo")',15000);
        else
        if ('[ITEM_PLAYING_LEN]' == '[ITEM_PLAYING_POS]' && '[ITEM_PLAYING_LEN]' != '?' && '[ITEM_PLAYING_LEN]' != '0')
            setTimeout('pc()',500);
    }
      
getElementById('status').innerHTML = '[ Playing ' + i_p +  ' / [PLAYLIST_PLAYING_ITEMS_COUNT] ]';
}
else if ([IS_PAUSED]) { // adjust progressbar width if paused
set_np_width([ITEM_PLAYING_POS], [ITEM_PLAYING_LEN]);
set_t_pos([ITEM_PLAYING_POS]);
getElementById('status').innerHTML = '[ Paused ' + i_p + ' / [PLAYLIST_PLAYING_ITEMS_COUNT] ]';
} else { // hide unnecessary track info if stopped
counter = getElementById("counter");
if (counter)
counter.innerHTML = "";
getElementById("status").innerHTML = "[ Stopped ]";
getElementById("npstr").style.visibility = "hidden";
}

if ([IS_ENQUEUEING] && ('[AUTO_REFRESH]' != '') ) {
getElementById('status').innerHTML = '[ Enqueuement in progress ] ' + getElementById('status').innerHTML;
setTimeout('pc()',5000);
}

track = getElementById("track_title");

if (track && track.innerHTML == '' && ([IS_PLAYING] || [IS_PAUSED]) && ('[AUTO_REFRESH]' != '')) // if playing but track info is not loaded yet, reload page
setTimeout('pc()',500);

npp = getElementById("np"); // adjust progressbar width and height, and opacity hack for IE6
if (npp)
with (npp.style) {
if (getElementById("np").offsetHeight >= 2 )
height=getElementById("np").offsetHeight*2-2+"px";
left=getElementById("npd").offsetLeft+"px";
filter = "alpha(opacity=50)";
}
}

I search all the fay, I promess, i'm tired really, it's 01:55am, i'm on it since yesterday or maybe more.

If someone can just show me for one command, play for example. I just want to know how this is work, if it's work off course. I like to learn, I try search myself, but here i'm really off.

So, I resume. I would know if it's possible on the internet PSP browser, to press a button wich send a command without refresh the page and without ajax. If you can show me with one of the twos links, that's will be perfect.

Really thanks in advance. I go to sleep. Hope someone can help me on that, it's really important for me.

Again, sorry for my english.

Best regards.






« Last Edit: October 24, 2009, 04:03:57 PM by Ziltoid » Logged


AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #1 on: October 24, 2009, 07:13:01 PM »

I can read JS(since I'm not retarded) but I never learned to write it.

I brifely reviewed the html source of the pages created by this plugin and wrote a quick test app in Ruby to make sure I knew what everything was doing.  Frankly if I had a bloody cat5 cable I'd hook up my router and write a homebrew app to control Foobar through this plugin.  The interface is actually very simple and I don't think you're ever going to coerce the Sony browser to do what it is that you want.

To issue a command to the player you need a command name and a parameter.  We'll call them 'cmd' and 'par'.

Connect to the pc running the app on the deisgnated port (8888 by default) and send the string produced by

printf("GET /?cmd=%s&param1=%s HTTP/1.1\r\n\r\n", cmd, par);

If there is no parameter then the par is "".

At that point the socket can be closed and the player will execute the command.

Some information can be gleaned from the html response, such as list items or track length.  The html can be fetched in response to any command or else in response to a blank command (cmd = "").

These are the available commands in format

'cmd'('par' description) - further description

Code:
Start(track) //track num must be fetched from html (index starts at zero)
QueueItems(track)
DequeueItems(track)
MoveCursor(track)
Del(track)
Seek(percent_int)
Stop()
PlayOrPause()
Start()
StartPrevious()
StartNext()
StartRandom()
PlaybackOrder(0) - Default
PlaybackOrder(1) - Repeat (playlist)
PlaybackOrder(2) - Repeat (track)
PlaybackOrder(3) - Random
PlaybackOrder(4) - Shuffle (tracks)
PlaybackOrder(5) - Shuffle (albums)
PlaybackOrder(6) - Shuffle (folders)
Volume(percent_int)
SAC(0) - don't stop after current track
SAC(1) - stop after current track
SAQ(0) - don't stop after current queue
SAQ(1) - stop after current queue
QueueAlbum()
QueueRandomItems(num_of_items)
EmptyPlaylist()
SwitchPlaylist(num_by_list) //list must be fetched from html, index starts at zero, does not play new list, just changes focus to that list
Browse()
SearchMediaLibrary("search string") //string must be in http req style
QueryRetrace()
QueryAdvance(list_index) //list must be fetched from html
P(page num) - if the playlist is longer than one page this moves to a specific page.  index starts at 1

It should be relatively simple to write a program that sends commands 'blindly' and then write a tool to fetch info from the html, then all that remains is to create a decent user interface.

Frankly this sounds like a job for LuaPlayer.  Wink

I'd write this myself, but at the moment I don't have the needed equipment to get my PSP wifi connected to anything.  If you want to take a whack at it I can certainly help out with info on how to use http and write a simple GUI.
« Last Edit: October 24, 2009, 08:37:45 PM by AlphaDingDong » Logged
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« Reply #2 on: October 25, 2009, 12:24:07 AM »

Hi.

Thanks for your quick reply.

I'm feeling less alone now. I'm thinking about write an homebrew in LUA. There is an existing project here:
http://forums.exophase.com/showthread.php?t=837

But no working on my 5.50, same thing if I change the LUA player, the PSP cannot connect to my accec point.

The fact is, I like the idea I can make a simple interface in html, with my own photoshop skills. I create some buttons, the background and it's stay very free to change or make many skins.

If I can make my own skins easily than http on LUA player, so maybe I take a look to LUA code. But at the moment, my best option is to find a way for send a command without any refresh, without ajax or jquery.

If you say that's really better to create a LUA homebrew, I'll do that.

Have you take a look to the "flash/java" solution, the second link ?

Thanks a lot for your support.

Best regards.

EDIT: I found, this is that which send the commands:
Code:
function pc(c, p) {
var com = c || ''; var par = p || '';
with (document.cmd_form)
{
cmd.value = com;
param1.value = par;
submit();
}
}

And on my html, this is the "onclick=pc(this.name);".

I try delete all js parts and only this work. I learn like that.^^

But this part is more confuse to me:

Code:
<body onload="mouse_capture_init(); fit();" onresize="fit();">
<form action="/" method="get" name="cmd_form" target="_self" class="frm">

Now I must find a way for blindly send this commands without refresh.^^

« Last Edit: October 25, 2009, 01:33:29 AM by Ziltoid » Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #3 on: October 25, 2009, 02:39:02 AM »

Code:
<body onload="mouse_capture_init(); fit();" onresize="fit();">
<form action="/" method="get" name="cmd_form" target="_self" class="frm">
The first line there just runs some initializer functions and sets up a routine that makes sure the page gets resized if the browser window is resized.  The mouse capture business looks like it just starts up a routine that keeps track of where the mouse is located horizontally.  I'm guessing that mouseX is referred to when you click the progress bar to seek a new position in the playing track.

The second line sets up some parameters for the form that the interface is embedded in.  It just tells the program some specifics on how to react when you take an action.

I dunno.  Maybe there's a way to do what you're saying, but I'm not a java expert.

I can Lua though.  I can't download that Lua project you linked.  Can you post a copy?  Maybe I can get it to work for you.
Logged
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« Reply #4 on: October 25, 2009, 02:54:45 AM »

Thanks for your reply.

I've maybe a solution but I need your advices.

I find that:
Code:
<script language="javascript" type="text/javascript">
        function include(script_filename) {
            document.write('<' + 'script');
            document.write(' language="javascript"');
            document.write(' type="text/javascript"');
            document.write(' src="' + script_filename + '">');
            document.write('</' + 'script' + '>');
        }
 
        function include_dom(script_filename) {
            var html_doc = document.getElementsByTagName('head').item(0);
            var js = document.createElement('script');
            js.setAttribute('language', 'javascript');
            js.setAttribute('type', 'text/javascript');
            js.setAttribute('src', script_filename);
            html_doc.appendChild(js);
            return false;
        }
        </script>

With that:
Code:
<li style="cursor: pointer" onclick="include_dom('1.js')">Click for 1.js using DOM</li>

The 1.js only contain:

alert('test');

So when we click on the line, this call the 1.js dynamicly. This working perfect on PC but I can't make this working on the PSP browser...

Here is the link for the LUA project:

http://rapidshare.com/files/297639957/13159_Foobar2000_Remote_Interface_v1.2.zip.html

Thanks for your help.

Best regards.

EDIT: another thing, but I don't know how to adapt to my problem, but it seems working on the PSP browser.
http://www.brothercake.com/reference/psp/dynamic.html

And I find that line is important too:
Code:
<input name="cmd" type="hidden" value=""><input name="param1" type="hidden" value="">

EDIT2:

I found another tip that seems to work on my  PSP browser but don't kno how can I use it:
http://www.brothercake.com/site/resources/scripts/lojax/#get-the-script
« Last Edit: October 25, 2009, 08:19:51 AM by Ziltoid » Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #5 on: October 25, 2009, 11:18:13 PM »

I don't know anything about any of these things you've linked.  You may have more success on a Java oriented forum.

I'll look into this Lua script you linked though.
Logged
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« Reply #6 on: October 26, 2009, 01:49:58 AM »

Hi!

I'm happy !

A dev on the PSPGen forum help me and give me a solution wich working good.

First we must use the hacked radio player wich working with official and CFW firmware. Named ifreeRadio 1.8. Very easy to use, just put the files to the root of memory stick and launch this from the radio icon.

Then with this version you have access to amore advanced web browser wich have some interesting javascript commands.

Now just browse to your foo_httpcontrol template >http://myip:8888/ .

On your template now, just for testing the command, create thats lines:

CODE
<object name="radio" type="application/x-psp-extplugin"></object>

and

CODE
<input type="button" value="test" onclick="radio.sysRadioPrepareForHttpGet('http://monip/?cmd=PlayOrPause&param1=')"/>

This is just for testing the play/pause button. For the other commands see that:



Just replace the PlayOrPause with others commands and create your own template !

And another best solution for me find by the autor of the plugin:

http://atz.ath.cx:8282/foo_httpcontrol/lojax

Thanks again.

Best regards.
Logged
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« Reply #7 on: October 31, 2009, 11:21:05 AM »

Hi, Have you take a look to the LUA homebrew ?

My project is very hard to make work. I achieved the most hard part, but PSP radio browser have not enough memory for my template...

So I'm back to the begining of my problem.

Thanks.

Best regards.
Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #8 on: October 31, 2009, 12:49:37 PM »

The one you linked doesn't work with httpcontrol.  It uses a different foobar plugin.

Can you run LuaPlayer Euphoria on your PSP?

Please check to see if it will run and if it can connect to your router.

http://dl.qj.net/LuaPlayer-Euphoria-v4/pg/49/fid/27087/catid/151
Logged
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« Reply #9 on: October 31, 2009, 02:36:36 PM »

No, he doesn't.

Have this error:

Error:SCRIPT.LUA:6:pspSdkInetInit Failed.

Thanks for you help.

Best regards.
Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #10 on: November 01, 2009, 12:58:00 PM »

Oh sorry.  LPE doesn't have net support yet.

How about HM 8:

http://www.ultimatepsp.fr/jeremie-upsp/J3r3mie/Divers/Download/LPHM8.zip
Logged
Ziltoid
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
917.90 points

View Inventory
Send Money to Ziltoid

View Profile
« Reply #11 on: November 05, 2009, 04:56:42 AM »

Thanks for reply.

It's ok, I use the foo http control now.

Thanks for your help.

Best regards.
Logged
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 3.416 seconds with 35 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com