0

Can I invoke a URL, directly from javascript without using AJAX,on click of a play button, i am calling the playAlbumFromMediaUrl().

function playAlbumFromMediaUrl() {
    var trackMasterList = document.audioDetails.trackMasterIdList.value;

    var stringUrl = trackMasterList.split('::');


    for (var i = 0; i < stringUrl.length - 1; i++) {

        playlist[i] = {
            file: stringUrl[i],
            provider: "/teams/web/jwplayer/AkamaiAdvancedJWStreamProvider.swf"
        }

    }
    setTimeout(function () {
        jwplayerSetupForPlayAlbum();
    }, 1000);
}


function jwplayerSetupForPlayAlbum() {
    jwplayer('html5AudioPlayer').setup({
        playlist: [{
            file: "http://localhost:8080/servlet/MediaLibraryAccessServlet?trackMasterId=898035&isProtocol=rtmpe&assetFormat=MP448Full",
            provider: "/teams/web/jwplayer/AkamaiAdvancedJWStreamProvider.swf"
        }],
        width: 550,
        height: 30
    }).play();


}

Once the url is invoked,it calls the MediaLibraryAccess servlet class that returns a mp4 url, that can be played by the jwplayer.

I need to invoke the servlet url,without using AJAX. For simplicity, i am not looping the playlist,instead i hard coded the servlet URL call in the jwplayer file attribute.

Can anyone help with this.

BackSlash
  • 21,927
  • 22
  • 96
  • 136
  • The trackMasterIdList contains a list of URL to be invoked. Below is a sample list, http://localhost:8080/servlet/MediaLibraryAccessServlet?trackMasterId=898035&isProtocol=rtmpe&assetFormat=MP448Full:: http://localhost:8080/servlet/MediaLibraryAccessServlet?trackMasterId=898037&isProtocol=rtmpe&assetFormat=MP448Full:: http://localhost:8080/servlet/MediaLibraryAccessServlet?trackMasterId=898039&isProtocol=rtmpe&assetFormat=MP448Full:: http://localhost:8080/servlet/MediaLibraryAccessServlet?trackMasterId=898041&isProtocol=rtmpe&assetFormat=MP448Full:: – user2236779 Sep 17 '13 at 19:27
  • Looks like the same issue as [this past question][1]. [1]: http://stackoverflow.com/questions/133310/how-can-i-get-jquery-to-perform-a-synchronous-rather-than-asynchronous-ajax-re – Dan Sep 17 '13 at 19:34
  • Dan,Looks like they are using jquery or Frames.I dont want to use them either.Is there a way to directly call the URL, so it invokes the servlet. – user2236779 Sep 17 '13 at 20:16

1 Answers1

0

As far as i know there are 4 basic ways to call a URL.

  1. Direct POST/GET (normal clicking of a link)
  2. Using frames
  3. Using Ajax
  4. Opening a pop-up window that will call the URL with one of the above methods.

Eliminating option 2-3 you are left with only option 1 witch I doubt that it will fill your needs. I think you should spend some times and make it work using options 2 or 3

UPDATE:

To use option 1 or 4 using javascript see Window.location.href and Window.open () methods in JavaScript

In short for Option 1 you can use:

window.location.href = 'http://www.google.com'; //Will take you to Google using GET.
Community
  • 1
  • 1
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
  • Hi MaVRoScy, Can I use the first option to directly call the URL http://localhost:8080/servlet/MediaLibraryAccessServlet?trackMasterId=898035&isProtocol=rtmpe&assetFormat=MP448Full from the javascript method.If so,how can I do it by POST or GET. – user2236779 Sep 19 '13 at 14:27
  • Thanks MaVRoSCy. I am able to hit the MediaLibraryAccessServlet class using window.location.href, but it should return a mp4 url, which I assign it to the file of the jwplayer. So,should i have to use response.sendRedirect(html5playListUrl) OR out.write(html5playListUrl), to return from the servlet class. – user2236779 Sep 19 '13 at 16:50
  • both ways will do, the `response.sendRedirect` method though will cause the client make an extra call. If you can do it with the first method then it is recomended – MaVRoSCy Sep 20 '13 at 05:51
  • I need to return only the StringUrl from the servlet class.So what should I use.I dont want to use response.sendRedirect() as it does another call. – user2236779 Sep 20 '13 at 14:18