XBMC Erweiterung des Webinterfaces um Hotkeys

Um die wichtigsten Aktionen auf dem XBMC über das Webinterface auszuführen, muss die Datei am Ende des Artikels heruntergeladen und in das Verzeichnis: /E/XBMC/web entpackt werden. Gegebenenfalls die alte default.asp sichern!

Die modifizierte default.asp erweitert um folgende Tastaturkürzel („Hotkeys“):

  • ↑  = Item Up
  • ↓ = Item Down
  • ← = Item Left
  • → = Item Right
  • Space = Return to previous menu
  • Return = Play/select current item
  • + = Volume Up
  • – = Volume Down

(Siehe dazu Zeile 079 – 131; 136-137)

Leider wird bei der Lautstärkeregelung der initiale Lautstärkewert nicht übernommen. Das heißt, dass der Lautstärkepegel zuerst automatisch auf 50% abgesenkt bzw. angehoben wird. +/- verändert ihn anschließend um jeweils 5%.

DOWNLOAD: Modifizierte default.asp v1.0.0

Der Quelltext:


<%
    if (isset("Action")) {
        if (Action == "UnqueMusicplaylist") {
            var ItemCount;
            var z;
            ItemCount = xbmcCommand("catalog","items");
            for (z = 0;  z < ItemCount;  z = z + 1) {
                // dirty workaround, cause unque, + z won't work
                xbmcCommand("navigate", Action);
                xbmcCommand("catalog","unque");
            }
            Action = "musicplaylist";          
        }
        xbmcCommand("navigate", Action);
    }
    
    if (isset("command")) {
        // execute a few commands before listing the contents
        if (command == "select") {
            xbmcCommand("catalog", "select," + item);
        } else if (command == "unque") {
            xbmcCommand("catalog", "unque," + item);
        }
    }

    var navigatorstate;
    var BannerClass;
    var InfoClass;
    var BackgroundClass;
    var ItemFileClass;
    navigatorstate = xbmcCommand("navigatorstate");

    if (isset("DisplayConfiguration")) {
        BannerClass = "SiteBannerConfiguration";
        InfoClass = "SiteInfoConfiguration";
        BackgroundClass = "SiteBackgroundConfiguration";
    } else if (navigatorstate == "pictures") {
        BannerClass = "SiteBannerMyPictures";
        InfoClass = "SiteInfoMyPictures";
        BackgroundClass = "SiteBackgroundMyPictures";
        ItemFileClass = "ItemFileMyPictures";
    } else if (navigatorstate == "music") {
        BannerClass = "SiteBannerMyMusic";
        InfoClass = "SiteInfoMyMusic";
        BackgroundClass = "SiteBackgroundMyMusic";
        ItemFileClass = "ItemFileMyMusic";
    } else if (navigatorstate == "videos") {
        BannerClass = "SiteBannerMyVideos";
        InfoClass = "SiteInfoMyVideos";
        BackgroundClass = "SiteBackgroundMyVideos";
        ItemFileClass = "ItemFileMyVideos";
    } else if (navigatorstate == "musicplaylist") {
        BannerClass = "SiteBannerMusicPlaylist";
        InfoClass = "SiteInfoMusicPlaylist";
        BackgroundClass = "SiteBackgroundMusicPlaylist";
        ItemFileClass = "ItemFileMusicPlaylist";
    } else if (navigatorstate == "videoplaylist") {
        BannerClass = "SiteBannerVideoPlaylist";
        InfoClass = "SiteInfoVideoPlaylist";
        BackgroundClass = "SiteBackgroundVideoPlaylist";
        ItemFileClass = "ItemFileVideoPlaylist";
    } else {
        BannerClass = "SiteBannerNone";
        InfoClass = "SiteInfoLogo";
        BackgroundClass = "SiteBackgroundHome";
    }

%><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title> Xbox Media Center - Remote Control </title>
        <link href="styles/Project%20Mayhem/screen.css" rel="stylesheet" type="text/css" />
        <link rel="shortcut icon" href="/styles/Project%20Mayhem/images/ShortcutIcon.ico" type="image/x-icon" />        

        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<script language="JavaScript">
var volume = 50;

// David Kirberich, 28.11.2010, Germany.
// Feel free to modify!

document.onkeydown = function ( event ) {
event = event || window.event;

// To test the keyCode parameter:
//alert(event.keyCode);

if (event.keyCode == 13) // ENTER
{
document.getElementById('control_iframe').src = '/xbmcCmds/xbmcHttp?command=sendKey(256)';
}
if (event.keyCode == 32) // SPACE
{
document.getElementById('control_iframe').src = '/xbmcCmds/xbmcHttp?command=sendKey(257)';
}
if (event.keyCode == 37) // LEFT
{
document.getElementById('control_iframe').src = '/xbmcCmds/xbmcHttp?command=sendKey(272)';
}
if (event.keyCode == 38) // TOP
{
document.getElementById('control_iframe').src = '/xbmcCmds/xbmcHttp?command=sendKey(270)';
}
if (event.keyCode == 39) // RIGHT
{
document.getElementById('control_iframe').src = '/xbmcCmds/xbmcHttp?command=sendKey(273)';
}
if (event.keyCode == 40) // DOWN
{
document.getElementById('control_iframe').src = '/xbmcCmds/xbmcHttp?command=sendKey(271)';
}
if (event.keyCode == 107) // +
{
	if (volume < 100)
	{
		volume += 5;
		document.getElementById('volume_iframe').src = '/xbmcCmds/xbmcHttp?command=setVolume(' + volume + ')';
	}
}
if (event.keyCode == 109) // -
{
	if (volume > 0) {
		volume -= 5;
		document.getElementById('volume_iframe').src = '/xbmcCmds/xbmcHttp?command=setVolume(' + volume + ')';
	}
}
}
</script>
    </head>
  
    <body>

<iframe id="control_iframe" style="height: 0px; width: 0px" src="about:blank"></iframe>
<iframe id="volume_iframe" style="height: 0px; width: 0px" src="about:blank"></iframe>

        <div id="SiteContainer" class="<% write(BackgroundClass); %>">

            <div id="SiteLeftContainer">
                <div id="SiteInfoContainer">
                    <div id="<% write(InfoClass); %>"></div>
                </div>
    
                <div id="SiteMenuContainer">
                    <ul>
                        <li class="MyPictures"><a href="default.asp?Action=pictures"><span>My Pictures</span></a></li>
                        <li class="MyMusic"><a href="default.asp?Action=music"><span>My Music</span></a></li>
                        <li class="MyVideos"><a href="default.asp?Action=videos"><span>My Videos</span></a></li>
                        <li class="MusicPlaylist"><a href="default.asp?Action=musicplaylist"><span>Music Playlist</span></a></li>
                        <li class="VideoPlaylist"><a href="default.asp?Action=videoplaylist"><span>Video Playlist</span></a></li>
                    </ul>
                </div>
      
                <div id="SiteControlContainer">
                    <ul>
                        <li class="Stop"><a href="/xbmcCmds/xbmcForm?command=stop" target="CommandFrame"><span>Stop</span></a></li>
                        <li class="Play"><a href="/xbmcCmds/xbmcForm?command=play" target="CommandFrame"><span>Play</span></a></li>
                        <li class="Pause"><a href="/xbmcCmds/xbmcForm?command=pause" target="CommandFrame"><span>Pause</span></a></li>
                        <li class="Previous"><a href="/xbmcCmds/xbmcForm?command=previous" target="CommandFrame"><span>Previous</span></a></li>
                        <li class="Next"><a href="/xbmcCmds/xbmcForm?command=next" target="CommandFrame"><span>Next</span></a></li>
                    </ul>
                </div>
            
                <div id="SiteSubMenuContainer">
                    <ul>
                        <li class="Subpanel"><a href=""><span>Subpanel</span></a>
                            <ul>
                                <li><a href="SubRemote"><span>Remote</span></a></li>
                                <li><a href="SubConfiguration"><span>Configuration</span></a></li>
                                <li><a href="/xbmcCmds/xbmcForm?command=exit" target="CommandFrame"><span>Dashboard</span></a></li>
                                <li><a href="/xbmcCmds/xbmcForm?command=reboot" target="CommandFrame"><span>Reboot</span></a></li>
                            </ul>
                        </li>
                        
                        <li class="Configuration"><a href="default.asp?DisplayConfiguration=true"><span>Configuration</span></a></li>
                        <li class="Dash"><a href="/xbmcCmds/xbmcForm?command=exit" target="CommandFrame"><span>Dash</span></a></li>
                        <li class="Reboot"><a href="/xbmcCmds/xbmcForm?command=restart" target="CommandFrame"><span>Reboot</span></a></li>
			<li class="Shutdown"><a href="/xbmcCmds/xbmcForm?command=shutdown" target="CommandFrame"><span>Shutdown</span></a></li>
                    </ul>
                </div>
    
            </div>
            
    
    
            <div id="SiteRightContainer">
            
                <div id="SiteBannerContainer">
                    <div id="<% write(BannerClass); %>"></div>
                </div>
                
                <div id="SiteContentContainer">
<%

  if (isset("DisplayConfiguration") ) {


    /*
     * xbmc configuration options
    
      xbmcCfgBookmarkSize(type)
      xbmcCfgGetBookmark(type, parameter, id)
      xbmcCfgAddBookmark(type, name, path [, position])
      xbmcCfgSaveBookmark(type, name, path, position)
      xbmcCfgRemoveBookmark(type, position)
      xbmcCfgSaveConfiguration(filename)
      xbmcCfgGetOption(name)
      xbmcCfgSetOption(name, value)
    
     */
    
    write("<a href='default.asp?DisplayConfiguration=true&page=bookmarks'>bookmarks</a> \n");
    write("<a href='default.asp?DisplayConfiguration=true&page=options'>xbmc options</a> \n");
    write("<a href='default.asp?DisplayConfiguration=true&page=load_save'>load / save</a> \n");

    write("<br />\n");
    write("<br />\n");
    
    
    /* if action isset we want to save / edit or remove something */
    if (isset("action"))
    {
      if (action == "savebookmark")
      {
        if (isset("name") == "1" && isset("path") == "1" && isset("type") == "1" && isset("position") == "1")
        {
          xbmcCfgSaveBookmark(type, name, path, position);
        }
        else
          write("Error");
      }
      if (action == "addbookmark")
      {
        if (isset("name") == "1" && isset("path") == "1" && isset("type") == "1")
        {
          xbmcCfgAddBookmark(type, name, path);
        }
        else
          write("Error");
      }
      if (action == "remove")
      {
        if (isset("page"))
        {
          // return to bookmark page and not to editbookmarks
          page = "bookmarks";
          xbmcCfgRemoveBookmark(type, position);
        }
      }
      if (action == "saveoptions")
      {
        xbmcCfgSetOption("home", home);
        xbmcCfgSetOption("CDDBIpAdres", CDDBIpAdres);
    
        var usef = "no";
        if (isset("useFDrive")) usef = "yes";
        xbmcCfgSetOption("useFDrive", usef);
    
        var useg = "no";
        if (isset("useGDrive")) useg = "yes";
        xbmcCfgSetOption("useGDrive", useg);
    
        xbmcCfgSetOption("dashboard", dashboard);
        xbmcCfgSetOption("dvdplayer", dvdplayer);
        xbmcCfgSetOption("subtitles", subtitles);
        xbmcCfgSetOption("startwindow", startwindow);
        xbmcCfgSetOption("pictureextensions", pictureextensions);
        xbmcCfgSetOption("musicextensions", musicextensions);
        xbmcCfgSetOption("videoextensions", videoextensions);
        xbmcCfgSetOption("thumbnails", thumbnails);
        xbmcCfgSetOption("shortcuts", shortcuts);
        xbmcCfgSetOption("albums", albums);
        xbmcCfgSetOption("recordings", recordings);
        xbmcCfgSetOption("screenshots", screenshots);
    
        var remcodes = "no";
        if (isset("displayremotecodes")) remcodes = "yes";
        xbmcCfgSetOption("displayremotecodes", remcodes);
      }
      if (action == "save")
      {
        xbmcCfgSaveConfiguration("XBoxMediaCenter.xml");
      }
    }
    
    if (isset("page"))
    {
      var i;
      var name;
      var value;
      var options;
    
      if (page == "bookmarks")
      {
        var musicbookmarks = xbmcCfgBookmarkSize("music");
        var picturebookmarks = xbmcCfgBookmarkSize("pictures");
        var videobookmarks = xbmcCfgBookmarkSize("video");
        var filebookmarks = xbmcCfgBookmarkSize("files");
        var programbookmarks = xbmcCfgBookmarkSize("myprograms");
        
    
        /* Add new Bookmark button */
        write("<form name='new_bookmark' method='post' action='default.asp?DisplayConfiguration=true&page=addbookmark'>\n");
        write("  <input type='submit' name='addnewbookmark' value='Add new bookmark'><br>\n");
        write("</form>\n");
    
        /* Display Music Bookmarks */
        write("<form name='music_bookmarks' method='post' action='default.asp?DisplayConfiguration=true&page=editbookmark&type=music'>\n");
        write("  Music Bookmarks:<br>\n");
        write("  <input type='submit' name='action' value='edit'>\n");
        write("  <input type='submit' name='action' value='remove'>\n");
        write("  <select name='position'>\n");
        i = 0;
        for (i=1; i<=musicbookmarks; i=i+1)
        {
          write("    <option value=" + i + ">" + xbmcCfgGetBookmark("music", "name", i) + "</option>\n");
        }
        write("  </select>\n");
        write("</form>\n");
    
        /* Display Picture Bookmarks */
        write("<form name='picture_bookmarks' method='post' action='default.asp?DisplayConfiguration=true&page=editbookmark&type=pictures'>\n");
        write("Picture Bookmarks:<br>\n");
        write("  <input type='submit' name='action' value='edit'>\n");
        write("  <input type='submit' name='action' value='remove'>\n");
        write("  <select name='position'>\n");
        i = 0;
        for (i=1; i<=picturebookmarks; i=i+1)
        {
          write("    <option value=" + i + ">" + xbmcCfgGetBookmark("pictures", "name", i) + "</option>\n");
        }
        write("  </select>\n");
        write("</form>\n");
    
        /* Display Video Bookmarks */
        write("<form name='video_bookmarks' method='post' action='default.asp?DisplayConfiguration=true&page=editbookmark&type=video'>\n");
        write("Video Bookmarks:<br>\n");
        write("  <input type='submit' name='action' value='edit'>\n");
        write("  <input type='submit' name='action' value='remove'>\n");
        write("  <select name='position'>\n");
        i = 0;
        for (i=1; i<=videobookmarks; i=i+1)
        {
          write("    <option value=" + i + ">" + xbmcCfgGetBookmark("video", "name", i) + "</option>\n");
        }
        write("  </select>\n");
        write("</form>\n");
    
        /* Display File Bookmarks */
        write("<form name='file_bookmarks' method='post' action='default.asp?DisplayConfiguration=true&page=editbookmark&type=files'>\n");
        write("File Bookmarks:<br>\n");
        write("  <input type='submit' name='action' value='edit'>\n");
        write("  <input type='submit' name='action' value='remove'>\n");
        write("  <select name='position'>\n");
        i = 0;
        for (i=1; i<=filebookmarks; i=i+1)
        {
          write("    <option value=" + i + ">" + xbmcCfgGetBookmark("files", "name", i) + "</option>\n");
        }
        write("  </select>\n");
        write("</form>\n");
    
        /* Display Program Bookmarks */
        write("<form name='program_bookmarks' method='post' action='default.asp?DisplayConfiguration=true&page=editbookmark&type=myprograms'>\n");
        write("Program Bookmarks:<br>\n");
        write("  <input type='submit' name='action' value='edit'>\n");
        write("  <input type='submit' name='action' value='remove'>\n");
        write("  <select name='position'>\n");
        i = 0;
        for (i=1; i<=programbookmarks; i=i+1)
        {
          write("    <option value=" + i + ">" + xbmcCfgGetBookmark("myprograms", "name", i) + "</option>\n");
        }
        write("  </select>\n");
        write("</form>\n");
      }
      else if (page == "options")
      {
        write("	<form action='default.asp?DisplayConfiguration=true' method='post' name='cfgform' id='cfgform'>" + \
              "		<input name='action' type='hidden' value='saveoptions'>" + \
              "		<input name='page' type='hidden' value='options'>" + \
              "		<table width='500'>");
        write("			<tr>" + \
              "				<td width='200'><label>Home</label></td>" + \
              "				<td><input name='home' type='text' value='"); write(xbmcCfgGetOption("home")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>CDDB IP Address</label></td><td>" + \
              "				<input name='CDDBIpAdres' type='text' value='"); write(xbmcCfgGetOption("CDDBIpAdres")); write("' size='25'><br></td>" + \
              "			</tr>");
    
        // Use F Drive
        write("			<tr>" + \
              "					<td><label>Use F Drive</label></td><td>" + \
              "           <input name='useFDrive' type='checkbox' value='true' ");
              if (xbmcCfgGetOption("useFDrive") == "yes")	write("checked>");
              else write(">");
        write("         <br></td>" + \
              "			</tr>");
    
        // Use G Drive
        write("			<tr>" + \
              "					<td><label>Use G Drive</label></td><td>" + \
              "           <input name='useGDrive' type='checkbox' value='true' ");
              if (xbmcCfgGetOption("useGDrive") == "yes")	write("checked>");
              else write(">");
        write("         <br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Dashboard</label></td>" + \
              "				<td><input name='dashboard' type='text' value='"); write(xbmcCfgGetOption("dashboard")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Dvdplayer</label></td>" + \
              "				<td><input name='dvdplayer' type='text' value='"); write(xbmcCfgGetOption("dvdplayer")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Subtitles</label></td>" + \
              "				<td><input name='subtitles' type='text' value='"); write(xbmcCfgGetOption("subtitles")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Startwindow</label></td>" + \
              "				<td><input name='startwindow' type='text' value='"); write(xbmcCfgGetOption("startwindow")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Picture Extensions</label></td>" + \
              "				<td><input name='pictureextensions' type='text' value='"); write(xbmcCfgGetOption("pictureextensions")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Music Extensions</label></td>" + \
              "				<td><input name='musicextensions' type='text' value='"); write(xbmcCfgGetOption("musicextensions")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Video Extensions</label></td>" + \
              "				<td><input name='videoextensions' type='text' value='"); write(xbmcCfgGetOption("videoextensions")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Thumbnails</label></td>" + \
              "				<td><input name='thumbnails' type='text' value='"); write(xbmcCfgGetOption("thumbnails")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Shortcuts</label></td>" + \
              "				<td><input name='shortcuts' type='text' value='"); write(xbmcCfgGetOption("shortcuts")); write("' size='25'><br></td>" + \
              "			</tr>" );
        write("			<tr>" + \
              "				<td><label>Albums</label></td>" + \
              "				<td><input name='albums' type='text' value='"); write(xbmcCfgGetOption("albums")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Recordings</label></td>" + \
              "				<td><input name='recordings' type='text' value='"); write(xbmcCfgGetOption("recordings")); write("' size='25'><br></td>" + \
              "			</tr>");
        write("			<tr>" + \
              "				<td><label>Screenshots</label></td>" + \
              "				<td><input name='screenshots' type='text' value='"); write(xbmcCfgGetOption("screenshots")); write("' size='25'><br></td>" + \
              "			</tr>");
    
        // Display remote codes
        write("			<tr>" + \
              "					<td><label>Display remote codes</label></td><td>" + \
              "           <input name='displayremotecodes' type='checkbox' value='true' ");
              if (xbmcCfgGetOption("displayremotecodes") == "yes")	write("checked>");
              else write(">");
        write("         <br></td>" + \
              "			</tr>");
    
        write("		</table><br>" + \
              "		<input type='submit' name='save' value='save'>" + \
              "	</form><br>");
      }
      else if (page == "editbookmark")
      {
        if (isset("type") == "1" && isset("position") == "1")
        {
          write("<form name='savebookmark' method='post' action='default.asp?DisplayConfiguration=true&page=bookmarks&action=savebookmark'>\n");
          write("<input name='position' type='hidden' value='" + position + "'>\n");
          write("<input name='type' type='hidden' value='" + type + "'>\n");
          write("  <table width='500' border='0'>\n");
          write("    <tr> \n");
          write("      <td><label>name</label></td>\n");
          write("      <td><input type='text' name='name' value='" + xbmcCfgGetBookmark(type, "name", position) + "'></td>\n");
          write("    </tr>\n");
          write("    <tr> \n");
          write("      <td><label>path</label></td>\n");
          write("      <td><input type='text' name='path' value='" + xbmcCfgGetBookmark(type, "path", position) + "'></td>\n");
          write("    </tr>\n");
          write("  </table><br>\n");
          write("  <input type='submit' name='save' value='save'>\n");
          write("</form>\n");
        }
      }
      else if (page == "addbookmark")
      {
        var data = "<form name='addbookmark' method='post' action='default.asp?DisplayConfiguration=true&page=bookmarks&action=addbookmark'>\n";
        data = data + "  <table width='500' border='0'>\n";
        data = data + "    <tr> \n";
        data = data + "      <td><label>Type</label></td>\n";
        data = data + "      <td>";
        data = data + "        <select name='type'>\n";
        data = data + "          <option value=files>File</option>\n";
        data = data + "          <option value=music>Music</option>\n";
        data = data + "          <option value=myprograms>Program</option>\n";
        data = data + "          <option value=pictures>Picture</option>\n";
        data = data + "          <option value=video>Video</option>\n";
        data = data + "        </select>\n";
        data = data + "      </td>\n";
        data = data + "    </tr>\n";
        data = data + "    <tr> \n";
        data = data + "      <td><label>Name</label></td>\n";
        data = data + "      <td><input type='text' name='name' value=''></td>\n";
        data = data + "    </tr>\n";
        data = data + "    <tr> \n";
        data = data + "      <td><label>Path</label></td>\n";
        data = data + "      <td><input type='text' name='path' value=''></td>\n";
        data = data + "    </tr>\n";
        data = data + "  </table><br>\n";
        data = data + "  <input type='submit' name='save' value='save'>\n";
        data = data + "</form>\n";
    
        write(data);
      }
      if (page == "load_save")
      {
        write("<br><br><a href='default.asp?DisplayConfiguration=true&action=save'>Save</a>\n");
      }
    }


  } else {
 
  
    var z;
    var n;
    var i;
    var data;
  
  
    n = xbmcCommand("catalog","items"); // number of items to list
    file = xbmcCommand("catalog","first");
    
    if ( n > 0) {
        write("                    <ul id=\"ItemList\">\n");
    }
    
    for (z=0; z<n; z=z+1)
    {
      var type = xbmcCommand("catalog","type," + z);
  
  
      data = "                        <li>";
  
      if (type != "directory") {
        // we have a file to play, send command to server when clicked and do not refresh the current page
        data = data + "<div class=\"" + ItemFileClass + "\"></div>";
      } else { 
        data = data + "<div class=\"ItemFolder\"></div>"; 
      }
  
  
      if (file != ".." && navigatorstate != "musicplaylist" && navigatorstate != "videoplaylist" && navigatorstate != "pictures") {
        data = data + "<div class=\"AddQueue\"><a href=\"/xbmcCmds/xbmcForm?command=catalog&parameter=que," + z + "\" target=\"CommandFrame\" title=\"add to queue\"><span>Q</span></a></div>";
      } else if (navigatorstate == "musicplaylist" || navigatorstate == "videoplaylist")	{
        data = data + "<div class=\"RemoveQueue\"><a href=\"default.asp?command=unque&item=" + z + "\" title=\"remove from queue\"><span>R</span></a></div>";
      }
  
  
      if (type != "directory") {
        // we have a file to play, send command to server when clicked and do not refresh the current page
        data = data + "<div class=\"FileName\"><a href=\"/xbmcCmds/xbmcForm?command=catalog&parameter=select," + z + "\" target=\"CommandFrame\">";
      } else { 
        data = data + "<div class=\"FileName\"><a href=\"default.asp?command=select&item=" + z + "\">"; 
      }
      
      data = data + file + "</a></div>";
      
      data = data + "</li>\n";
      write(data);
      
        
      file = xbmcCommand("catalog","next");
    }

    if ( n > 0) {
        write("                    </ul>\n");
    }
    
    if (navigatorstate == "musicplaylist") {
        write ("<a href=\"default.asp?Action=UnqueMusicplaylist\" id=\"UnqueMusciplaylist\"><span>Clear Playlist</span></a>\n");
    }


}
%>
                </div>
    
            </div>
            
        </div>
        
        <div id="SiteCommandContainer">
            <iframe src="about:blank" width="1" height="1" name="CommandFrame"></iframe>
        </div>
  
    </body>
</html>

Code39 Barcodes über ASP.NET (VB) ausgeben

Code39 über ASP.NET ausgeben
Code39 über ASP.NET ausgeben

Den folgenden Quelltext habe ich vor etwa 2 Jahren in seiner ursprünglichen Form in einem VBA-Forum gefunden und an VB.NET angepasst um in einer ASP.NET-Anwendung on-the-fly Barcodes auszugeben.
Vorteil von Code39 ist seine große Druck- und Lesetoleranz. Zwischenzeitlich hatte ich den Sourcecode auch einmal in C# umgeschrieben. Dieser ist allerdings bei einem Festplattendefekt verloren gegangen.


Private Function MD_Barcode39(ByVal Barcode As String, ByVal PaintObj As Object, _
ByVal mLeft As Single, ByVal mTop As Single, _
ByVal mWidth As Single, ByVal mHeight As Single)

Dim Nbar As Single, Wbar As Single, Qbar As Single, NextBar As Single
Dim CountX As Single, CountY As Single
Dim Parts As Single, Pix As Single, BarCodePlus As String
Dim Stripes As String, BarType As String
Dim Mx As Single, my As Single, Sx As Single, Sy As Single
Const Nratio = 20, Wratio = 55, Qratio = 35

Dim g As System.Drawing.Graphics
Dim pB As New System.Drawing.SolidBrush(System.Drawing.Color.Black)
Dim pW As New System.Drawing.SolidBrush(System.Drawing.Color.White)
Dim color As System.Drawing.SolidBrush

'Get control size and location properties.
Sx = mLeft
Sy = mTop
Mx = mWidth
my = mHeight

g = PaintObj

'Calculate actual and relative pixels values.
Parts = (Barcode.Length + 2) * ((6 * Nratio) + (3 * Wratio) + (1 * Qratio))
Pix = (Mx / Parts)
Nbar = (20 * Pix)
Wbar = (55 * Pix)
Qbar = (35 * Pix)

'Initialize bar index and color.
NextBar = Sx
color = pW

'Pad each end of string with start/stop characters.
BarCodePlus = "*" &amp; Barcode.ToUpper &amp; "*"

'Walk through each character of the barcode contents.
For CountX = 0 To BarCodePlus.Length - 1
'Get Barcode 1/0 string for indexed character.
Stripes = MD_BC39(BarCodePlus.Substring(CountX, 1))
For CountY = 0 To 8
'For each 1/0, draw a wide/narrow bar.
BarType = Stripes.Substring(CountY, 1)

'Toggle the color (black/white).
If color Is pW Then
color = pB
Else
color = pW
End If

Select Case BarType
Case "1"
'Draw a wide bar.
g.FillRectangle(color, NextBar, Sy, Wbar + NextBar, my + Sy)
NextBar = NextBar + Wbar
Case "0"
'Draw a narrow bar.
g.FillRectangle(color, NextBar, Sy, Nbar + NextBar, my + Sy)
NextBar = NextBar + Nbar
End Select
Next CountY

'Toggle the color (black/white).
If color Is pW Then
color = pB
Else
color = pW
End If

'Draw intermediate "quiet" bar.
g.FillRectangle(color, NextBar, Sy, Qbar + NextBar, my + Sy)
NextBar = NextBar + Qbar
Next CountX
End Function

Function MD_BC39(ByVal CharCode As String) As String
Dim BC39(90) As String

BC39(32) = "011000100" ' space
BC39(36) = "010101000" ' $
BC39(37) = "000101010" ' %
BC39(42) = "010010100" ' * Start/Stop
BC39(43) = "010001010" ' +
BC39(45) = "010000101" ' |
BC39(46) = "110000100" ' .
BC39(47) = "010100010" ' /
BC39(48) = "000110100" ' 0
BC39(49) = "100100001" ' 1
BC39(50) = "001100001" ' 2
BC39(51) = "101100000" ' 3
BC39(52) = "000110001" ' 4
BC39(53) = "100110000" ' 5
BC39(54) = "001110000" ' 6
BC39(55) = "000100101" ' 7
BC39(56) = "100100100" ' 8
BC39(57) = "001100100" ' 9
BC39(65) = "100001001" ' A
BC39(66) = "001001001" ' B
BC39(67) = "101001000" ' C
BC39(68) = "000011001" ' D
BC39(69) = "100011000" ' E
BC39(70) = "001011000" ' F
BC39(71) = "000001101" ' G
BC39(72) = "100001100" ' H
BC39(73) = "001001100" ' I
BC39(74) = "000011100" ' J
BC39(75) = "100000011" ' K
BC39(76) = "001000011" ' L
BC39(77) = "101000010" ' M
BC39(78) = "000010011" ' N
BC39(79) = "100010010" ' O
BC39(80) = "001010010" ' P
BC39(81) = "000000111" ' Q
BC39(82) = "100000110" ' R
BC39(83) = "001000110" ' S
BC39(84) = "000010110" ' T
BC39(85) = "110000001" ' U
BC39(86) = "011000001" ' V
BC39(87) = "111000000" ' W
BC39(88) = "010010001" ' X
BC39(89) = "110010000" ' Y
BC39(90) = "011010000" ' Z

Return BC39(Asc(CharCode))
End Function

Möchte man wie ich die Barcodes in einer ASP.NET-Anwendung ausgeben, kann folgender (schlampiger) Code als kleine Anregung verwendet werden:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim barcode As String = Request("barcode")
If Len(barcode) = 0 Then barcode = ""
Dim height As String = Request("height")
If (Len(height) = 0) Or (height > 768) Then height = 75
Dim width As String = Request("width")
If (Len(width) = 0) Or (width > 1024) Then width = 250
Dim plain As Boolean = True
Dim xh, xw As Integer
If Len(Request("plain")) <> 0 Then
If Request("plain") = 1 Then
plain = True
xw = width
xh = height
height = height + 15
Else
plain = False
End If
End If

Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb)

Dim g As Graphics = Graphics.FromImage(bmp)
MD_Barcode39(barcode, g, 0, 0, width, height)

If plain = True Then
Dim dispText As String = barcode
Dim dispFont As New Font("arial", 15, FontStyle.Regular, GraphicsUnit.Pixel)

g.FillRectangle(Brushes.White, 0, xh, xw, 15)

g.DrawString(dispText, dispFont, Brushes.Black, New PointF(0, xh))
End If

bmp.Save(Response.OutputStream, ImageFormat.Jpeg)
bmp.Dispose()
Response.End()
End Sub

In die @Page-Direktive muss noch ContentType=“image/jpeg“ hinzugefügt werden:


<%@ Page Language="VB" ContentType="image/jpeg" AutoEventWireup="true" CodeFile="barcode.aspx.vb" Inherits="barcode" %>

Aufrufen kann man das Dokument anschließend über den lokalen Webserver oder einen (externen) IIS. Der Aufruf vom Bild oben lautet:

http://localhost:12384/barcode.aspx?barcode=1234567890&width=400&plain=1