Search code examples
javascriptjqueryasp.net-mvc-5jwplayerjwplayer6

How to pass dynamic link to jwPlayer in mvc 5 using jquery


I am working on website using MVC 5 website is actually a video website which is suppose to load CDNSun storage videos.... How can i pass the dynamic link using "videoUrl" parameter..??? code is as follows :

$(document).ready(function () {
    jwplayer('mediaplayer').setup({
        'file': 'rtmp://872083564.r.cdnsun.net/872083564/_definst_/
                   mp4:872083564/(here i want to put videoUrl).mp4',
        'title': 'Title',
        'description': 'Description',
        'controlbar': 'bottom'
    });
});

Controller:

public ActionResult EpisodeList(Guid? id)
{
    IQueryable<VideoEpisodeDM> episodesdm = db.VideoEpisode
        .Where(ve => ve.VideoId == id);

    string video;

    foreach (var item in episodesdm)
    {
        video = item.Title;
        ViewBag.VideoUrl = item.VideoUrl;
    }


    return View(episodesdm.ToList());
}

Any help or help reference will be appreciated...thanks for your time in advance


Solution

  • Try one of two approaches:

    1. create the value in a tmp javascript variable

      <script type="text/javascript">
          $(document).ready(function () {
              var tmpVideo = "@iewBag.VideoUrl";
              tmpVideo = "872083564/" + tmpVideo + ".mp4";
              jwplayer('mediaplayer').setup({
                  'file': 'rtmp://872083564.r.cdnsun.net/872083564/_definst_/
                         mp4:tmpVideo,
                  'title': 'Title',
                  'description': 'Description',
                  'controlbar': 'bottom'
              });
          });
      

    Or just use curly brackets around your Razor code:

    <script type="text/javascript">
       $(document).ready(function () {
            jwplayer('mediaplayer').setup({
                'file': 'rtmp://872083564.r.cdnsun.net/872083564/_definst_/
                           mp4:872083564/@{ViewBag.VideoUrl}.mp4',
                'title': 'Title',
                'description': 'Description',
                'controlbar': 'bottom'
            });
        });