Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

 

The roCaptionRenderer component provides a mechanism for BrightScript channels to render closed captions in video played back with the roVideoPlayer.  Prior to the v 5.2 Roku firmware, captions could only be rendered in roVideoScreen.

Supported Interfaces

Supported Events

Description

Prior to the 5.2 Roku firmware version, closed captions could only be rendered in roVideoScreen.  Now channels that use roVideoPlayer embedded in an roScreen or roImageCanvas can also take advantage of Roku's closed captioning support.  roCaptionRenderer supports two different modes, which is set using the SetMode() method.  Depending on the mode set, and the type of screen being used, the BrightScript channel needs to do different levels of work to render captions.  These different workflows are highlighted in the tables below:

Mode 1
roScreenroImageCanvas
Call SetScreen()Call SetScreen()
Call UpdateCaption() 
Mode 2
roScreenroImageCanvas
All caption rendering is done by the channel's BrightScript codeAll caption rendering is done by the channel's BrightScript code

BrightScript channels do not create roCaptionRenderer instances directly using CreateObject().  Instead, when an roVideoPlayer is created, it contains an roCaptionRenderer.  BrightScript channels call ifVideoPlayer.GetCaptionRenderer() to get the caption renderer associated with their video player.

Sample Code

Function Main() as void
  mode = 1
  fonts = CreateObject("roFontRegistry")
  fonts.Register("pkg:/fonts/vSHandprinted.otf")
  font = fonts.GetFont("vSHandprinted", 28, 500, false)
  screen = CreateObject("roScreen", true)
  port = CreateObject("roMessagePort")
  screen.Clear(&h00)
  screen.SwapBuffers()
  screen.SetMessagePort(port)
  timer = CreateObject("roTimespan")
  screenSize = {}
  screenSize.width = screen.GetWidth()
  screenSize.height = screen.GetHeight()
  player = CreateObject("roVideoPlayer")
  player.SetContentList([
    {
        Stream : { url :"http://ecn.channel9.msdn.com/o9/content/smf/smoothcontent/elephantsdream/Elephants_Dream_1024-h264-st-aac.ism/manifest" }
        StreamFormat : "ism"
        TrackIDAudio: "audio_eng"
        TrackIDSubtitle: "ism/textstream_eng"
    }
  ])
  captions = player.GetCaptionRenderer()
  if (mode = 1)
    captions.SetScreen(screen)
  endif
  captions.SetMode(mode)
  captions.SetMessagePort(port)
  captions.ShowSubtitle(true)
  player.play()
  while true
    msg = wait(250, port)
    if type(msg) = "roCaptionRendererEvent"
      if msg.isCaptionText()
  print "isCaptionText"
  if msg.GetMessage() <> invalid and msg.GetMessage() <> ""
          DrawCaptionString(screen, screenSize, msg.GetMessage(), font)
   timer.Mark()
  else
   if timer.TotalSeconds() > 2
     ClearCaptionString(screen)
   endif
 endif
      else if msg.isCaptionUpdateRequest()
  print "isCaptionUpdateRequest()"
  UpdateCaptions(screen, captions)
      endif
    endif
end while
End Function
Function UpdateCaptions(screen as object, captions as object) as Void
  screen.Clear(&h00)
  captions.UpdateCaption()
  screen.SwapBuffers()
End Function
Function DrawCaptionString(screen as object, screenSize as object, caption as String, font as object) as Void
  screen.Clear(&h00)
  textHeight = font.GetOneLineHeight()
  textWidth = font.GetOneLineWidth(caption, screenSize.width)
  x = (screenSize.width - textWidth) / 2
  y = screenSize.height - textHeight
  screen.DrawText(caption, x, y, &hd5d522ff, font)
  screen.SwapBuffers()
End Function
Function ClearCaptionString(screen as object) as void
  screen.Clear(&h00)
  screen.SwapBuffers()
End Function

 

 

  • No labels