1

I am currently using SharePoint to query a pages library for a video, the aim is to then display this video in an iframe, I am currently using csom to get the video source from a Page, however this returns the code below:

<dl>
  <dt>MediaSource</dt>
  <dd>
    <a href="/Videos/Life Changing/video1.mp4">link</a>
  </dd>
  <dt>PreviewImageSource</dt>
  <dd>
    <a href="/Videos/Life Changing/Preview Images/snapshot.png">link</a>
  </dd>

  <dd>Inline</dd>
  <dt>AutoPlay</dt>
  <dd>False</dd>
  <dt>Loop</dt>
  <dd>False</dd>
  <dt>InlineHeight</dt>
  <dd>360px</dd>
  <dt>InlineWidth</dt>
  <dd>640px</dd>
  <dt>ShowEmbedControl</dt>
  <dd>True</dd>
  <dt>ConfigureFromContext</dt>
  <dd>False</dd>
  <dt>VideoSetSource</dt>
  <dd>
    <a href="/Videos/Life Changing">link</a>
  </dd>
</dl>

I need to extract the ".mp4" url and also the ".png" url so that I can use them in the iframe, how would be best to go about this please?

My code in full is:

    $(document).ready(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getVideoNews);
})


function getVideoNews() {
    context = SP.ClientContext.get_current();
    web = context.get_web();
    list = web.get_lists();
    list = web.get_lists().getByTitle('Pages');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View Scope=\'Recursive\'><RowLimit>5</RowLimit><ViewFields><FieldRef Name=\'Comments\' /><FieldRef Name=\'LikesCount\' /><FieldRef Name=\'FileRef\' /><FieldRef Name=\'Title\' /><FieldRef Name=\'Rich_x0020_Video_x0020_Embed\' /><FieldRef Name=\'Summary_x0020_Text\' /></ViewFields><Query><Where><Eq><FieldRef Name=\'ContentType\' /><Value Type=\'Text\'>News Video</Value></Eq></Where><OrderBy><FieldRef Name=\'Created\' Ascending=\'True\' /></OrderBy></Query></View>');
    camlQuery.set_folderServerRelativeUrl('News Videos');
    collListItem = list.getItems(camlQuery);
    context.load(list);
    context.load(collListItem);
    context.executeQueryAsync(
     Function.createDelegate(this, newsvideoSuccessHandler),
     Function.createDelegate(this, newsvideoErrorHandler));
}

function newsvideoSuccessHandler(result) {

    listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        oListItem = listItemEnumerator.get_current();

        var newsvideotitle = oListItem.get_item("Title");
        var newsvideolink = oListItem.get_item("FileRef");
        var newsvideo = oListItem.get_item("Rich_x0020_Video_x0020_Embed");

    }

}

function newsvideoErrorHandler(sender, args) {
    alert('Camelot News Video Error: \nRequest failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
0

This is the code i use to get videos info from a "Asset Library", maybe this can help you. I don't know how to get the preview pic but should be right there:

getDataFormVideosList:function(next){
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View>' +
                            '<ViewFields>' +
                                '<FieldRef Name=\'ID\' />' +
                                '<FieldRef Name=\'Title\' />' +
                            '</ViewFields>' +
                        '</View>');
    executeAsyncCamlQuery('your list name', camlQuery, null, function (err, items) {
        if (err) return next(err);

        var lListItemsInfo = [];
        var lListItemEnumerator = items.getEnumerator();
        while (lListItemEnumerator.moveNext()) {
            var lListItem = lListItemEnumerator.get_current();
            lListItemsInfo.push({
                id: lListItem.get_item('ID'),
                title: lListItem.get_item('Title')
            });
        }
        return next(null, lListItemsInfo);
    });
},
getVideo:function(next){
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View>' +
                            '<Query>' +
                                '<Where>' +
                                    '<Eq>' +
                                        '<FieldRef Name=\'ID\' />' +
                                        '<Value Type=\'Number\' >{YourIdGoesHere}</Value>' +
                                    '</Eq> ' +
                                '</Where>' +
                            '</Query> ' +
                            '<ViewFields>' +
                                '<FieldRef Name=\'ID\' />' +
                                '<FieldRef Name=\'Title\' />' +
                                '<FieldRef Name=\'VideoSetDescription\' />' +
                                '<FieldRef Name=\'EncodedAbsUrl\' />' +
                                '<FieldRef Name=\'FileRef\' />' +
                            '</ViewFields>' +
                        '</View>');

    var include = "Include(ID, Title, FileRef, EncodedAbsUrl, VideoSetDescription, FileSystemObjectType)";
    executeAsyncCamlQuery('your list name', camlQuery, include, function (err, items) {
        if (err) return next(err);

        var lListItemsInfo = {};
        var lListItemEnumerator = items.getEnumerator();
        lListItemEnumerator.moveNext();
        var lListItem = lListItemEnumerator.get_current();

        if(lListItem.get_fileSystemObjectType() == "1") {
            executeAsyncGetFiles(lListItem.get_item('FileRef'), null, function(err, files) {
                if (err) return next(err);

                var lFilesEnumerator = files.getEnumerator();
                lFilesEnumerator.moveNext();
                var lFile = lFilesEnumerator.get_current();

                //THIS IS THE OBJECT WITH YOUR VIDEO INFO***********
                lListItemsInfo = {
                    id: lListItem.get_item('ID'),
                    title: lListItem.get_item('Title'),
                    descripcion: lListItem.get_item('VideoSetDescription'),
                    url: lFile.get_serverRelativeUrl(),
                    extension: getFileExtension(lFile.get_serverRelativeUrl()),
                    folderUrl: lListItem.get_item('EncodedAbsUrl')
                };
                //***************************************************
                return next(null, lListItemsInfo);
            });
        }
    });
},
executeAsyncGetFiles: function (folderServerRelativeUrl, include, next) {
    try{
        var context = SP.ClientContext.get_current();
        var lWebSite = context.get_web();
        var lFolder = lWebSite.getFolderByServerRelativeUrl(folderServerRelativeUrl);
        var lFiles = lFolder.get_files();

        if (include)
            context.load(lFiles, include);
        else 
            context.load(lFiles);

        context.executeQueryAsync(function (sender, args) {
            if (next && typeof (next) == "function") next(null, lFiles);
        }, function (sender, args) {
            var lError = new Error('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
            if (next && typeof (next) == "function") next(lError);
            else throw (lError);
        });
    }
    catch (err) {
        return next(err);
    }

},
executeAsyncCamlQuery: function (listName, camlQuery, include, next) {
    try {
        var context = SP.ClientContext.get_current();
        var lWebSite = context.get_web();
        var lList = lWebSite.get_lists().getByTitle(listName);
        var lItems = lList.getItems(camlQuery);

        if (include)
            context.load(lItems, include);
        else 
            context.load(lItems);

        context.executeQueryAsync(function (sender, args) {
            if (next && typeof (next) == "function") next(null, lItems);
        }, function (sender, args) {
            var lError = new Error('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
            if (next && typeof (next) == "function") next(lError);
            else throw (lError);
        });
    } catch (err) {
        return next(err);
    }
},
getFileExtension: function(fileName) {
    return fileName.substr((~-fileName.lastIndexOf(".") >>> 0) + 2);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.