cancel
Showing results for 
Search instead for 
Did you mean: 

Types for audio and video

aussen2
Champ in-the-making
Champ in-the-making
I would like to suggest that you add general types for audio and video (ws:audio and ws:video) like you did for images (ws:image). For my current project I added theses types and the necessary changes were quite simple. But I also had to implement some minor additions to SectionType.java in order to get uploaded files specialized correctly according to their mimetype). It would be great if I would not have to re-implement these changes for every future release. 🙂


// Check to see if this is an image, audio or video
ContentReader reader = contentService.getReader(childNode, ContentModel.PROP_CONTENT);
if (reader != null && reader.exists())
{
    String mimetype = reader.getMimetype();
    if (mimetype != null && mimetype.trim().length() != 0)
    {
        if (isImageMimetype(reader.getMimetype()) == true)
        {
            // Make content node an image
            nodeService.setType(childNode, TYPE_IMAGE);
        }
        else if (isAudioMimetype(reader.getMimetype()) == true)
        {
            // Make content node an audio
            nodeService.setType(childNode, TYPE_AUDIO);
        }
        else if (isVideoMimetype(reader.getMimetype()) == true)
        {
            // Make content node a video
            nodeService.setType(childNode, TYPE_VIDEO);
        }
        else if (mimetypeMap.isText(reader.getMimetype()) == true)
        {
            // Make the content node an article
            nodeService.setType(childNode, TYPE_ARTICLE);
        }
    }
}


/**
* Indicates whether this is an image mimetype or not.
*
* @param mimetype
*            mimetype
* @return boolean true if image mimetype, false otherwise
*/
private boolean isImageMimetype(String mimetype)
{
    return mimetype.startsWith("image");
}
/**
* Indicates whether this is an audio mimetype or not.
*
* @param mimetype
*            mimetype
* @return boolean true if audio mimetype, false otherwise
*/
private boolean isAudioMimetype(String mimetype)
{
    return mimetype.startsWith("audio");
}

/**
* Indicates whether this is a video mimetype or not.
*
* @param mimetype
*            mimetype
* @return boolean true if video mimetype, false otherwise
*/
private boolean isVideoMimetype(String mimetype)
{
    return mimetype.startsWith("video");
}
2 REPLIES 2

bremmington
Champ on-the-rise
Champ on-the-rise
Thanks. Out of interest, what do you use this specialisation for?

aussen2
Champ in-the-making
Champ in-the-making
As with images I am assigning related audio and video files to articles via additional associations. I need the special types to make sure only valid assets can be selected for these associations by the users. These associated assets are then displayed within the article page with different HTML code that the template outputs according to their type. My types also contain additional properties like for example an Id of a YouTube version of a video. If that property has a value, the article page automatically embeds the YouTube version of the video instead of the HTML code to display the original video from the repository. The same approach is used for embedding audio and image files into the articles.