Monthly Archives: May 2012

Creating a Playlist For Windows Media Player With JavaScript

<div style="margin: 5px 0px 0px 0px; padding: 0px; color: #1753AC; font-size: 95%; font-weight: bold;">
Creating a Playlist For Windows Media Player With JavaScript</div>
<div id="post_message_2193236" style="font-size: 105%; margin: 15px 0px 0px 0px; line-height: 20px; word-wrap: break-word;">
<br />
Tony wrote:
<div style="margin:20px; margin-top:5px; border-left: 2px #ccc solid; padding-left: 10px; font-size: 90%; color: #666; line-height: 18px; ">
I'm working on project that plays movies using Windows Media Player 
and<br />
I'm controlling everything with JavaScript. Per the client I only 
need<br />
to support IE 6 or greater which happens to make things a bit 
easier.<br />
&gt;<br />
What I need to do is create a playlist and play it using JavaScript. 
I<br />
keep on getting close but not close enough to play the dang files. 
Has<br />
anyone done this before and can shed some light on what worked for 
them? </div>
If your playlist is to be the same every time with one video played<br />
after the other in sequence, your job will be easy and you need not<br />
limit to IE 6 + browsers.<br />
<br />
The WMP will play a few types of videos, with .wmv being the most<br />
common. This can use a wvx playlist file to play videos in sequence.<br />
For example the below object is used to play the WMV:<br />
<br />
&lt;div style="text-align:center"&gt;<br />
&lt;object data=""<br />
type="video/x-ms-wvx" style="width:400px; height:309px"&gt;<br />
&lt;param name="src" value=""<br />
valuetype="ref" /&gt;<br />
&lt;param name="showcontrols" value="1" valuetype="data" /&gt;<br />
&lt;param name="showstatusbar" value="1" valuetype="data" /&gt;<br />
&lt;param name="autostart" value="0" valuetype="data" /&gt;<br />
&lt;param name="volume" value="0" valuetype="data" /&gt;<br />
&lt;param name="PlayCount" value="1" valuetype="data" /&gt;<br />
&lt;/object&gt;<br />
&lt;/div&gt;<br />
<br />
Notice this uses the .wvx playlist file. A .wvx file has an XML<br />
structure and looks like:<br />
<br />
&lt;ASX VERSION="3.0"&gt;<br />
&lt;ENTRY&gt;<br />
&lt;REF HREF="" /&gt;<br />
&lt;/ENTRY&gt;<br />
&lt;/ASX&gt;<br />
<br />
I just put in one video, but you can add as many as you wish using the<br />
same entry-ref-/entry structure as above. The reference points to the<br />
location of the actual .wmv video files.<br />
<br />
Now if you want to change around the sequence in which the videos are<br />
played(say allow the viewer to select a play list from several video<br />
choices) you have more of a problem. The WMP is not easy to control<br />
with script if the code is to validate and play on most modern<br />
browsers. However, if you are interested in IE browsers only, as you<br />
state, then you likely can find information concerning scripting the<br />
WMP somewhere on the Microsoft developers site - at least it was there<br />
a few years ago. I wiil not use such code, but many will.<br />
<br />
An example of a working page that uses the above mentioned technique is<br />
<a href="" rel="nofollow" target="_blank"></a> . The<br />
page is designed for broadband with a bit rate of about 2 Mbps. It<br />
likely will work at much lower rates, but the buffering time will then<br />
become excessive until enough is downloaded to allow streaming to start<br />
without having to stop somewhere to catch up with loading. At least the<br />
player will indicate the progress of buffering so that you know the<br />
video is downloading.<br />

Array of hex chars from a function

 Private Sub btnCrtFunc_Click(sender As System.Object, e As System.EventArgsHandles btnCrtFunc.Click
        Dim result As New System.Text.StringBuilder
        result.Append("Hexadecimal characters: ")
        result.Append(String.Join(",", HexadecimalCharacters()))
        'Option I: Enumerate Hexadecimal Characters by line.
        For Each item As String In HexadecimalCharacters()
            With ListBox1
            End With
        'Option II: List Hexadecimal Characters as a string.
    End Sub
    Public Function HexadecimalCharacters() As String()
        ' ----- Return the first 16 hex numbers as an array.
        Dim hexChars(255) As String
        For counter As Integer = 0 To UBound(hexChars)
            hexChars(counter) = Hex(counter)
        Next counter
        Return hexChars
    End Function


Iterating Through Array Elements

Private Sub btnIterate_Click(sender As System.Object, _
        e As System.EventArgsHandles btnIterate.Click
        Dim result As New System.Text.StringBuilder
        Dim fruitArray() As String = { _
        For Each fruit As String In fruitArray
            result.AppendLine(fruit & ", ")
        Next fruit
        'The following codes creates a simple string array of 
        'fruit names, then processes each string in the array 
        'inside a For Each loop:
        ListBox1.Items.Add("Example I: Using a String.Builder" & _
                           "to create a single string object" & _
                           "combining all elements the array.")
        ListBox1.Items.Add("Example II: Simple Iteration showing individual array elements.")
        For Each item As String In fruitArray
            ListBox1.Items.Add(vbTab & item)
    End Sub

Sorting Array Elements

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgsHandles Button1.Click
        Dim result As New System.Text.StringBuilder
        Dim arrayToSort() As String = { _

        ' ----- Show the elements before sorting.
        result.AppendLine("Before sorting:")
        For Each fruit As String In arrayToSort
        Next fruit

        ' ----- Show the elements after sorting.
        result.AppendLine("After sorting:")
        For Each fruit As String In arrayToSort
        Next fruit

    End Sub
%d bloggers like this: