3

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

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
Suhail Mumtaz Awan
  • 3,295
  • 8
  • 43
  • 77

2 Answers2

4

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'
        });
    });
User
  • 276
  • 1
  • 6
2

Just use @ViewBag.VideoUrl in file and .mp4 should be in videoUrl. Works fine for me, and dont forget to use securetoken for security :-)

$(document).ready(function () {
        jwplayer('mediaplayer').setup({
            'file': 'rtmp://872083564.r.cdnsun.net/872083564/_definst_/
                       mp4:872083564/@ViewBag.VideoUrl',
            'title': 'Title',
            'description': 'Description',
            'controlbar': 'bottom',
    rtmp: {
                    securetoken: "some generated key"
                },
        });
    });
R3tep
  • 12,512
  • 10
  • 48
  • 75