*This is a separate SDK from the one I mentioned in https://community.roku.com/t5/Roku-Developer-Program/SVOD-Example-SDK-app-Issue-Crashes-after-subscr...)*
After running into the issue mentioned in my other thread, I threw some money to someone on Fiveer to create a custom SDK for my Roku channel. All great, works well. However, they have no experience in adding in Roku Pay.
Fine. Using the Subscription example SDK, I figured I could maybe do it.
Copied subscriptions.brs over
Called the channel store node in the main scene and imported the script in the xml.
All great.
Go searching for the videoshow function to add in the CheckSubscriptionAndStartPlayback stuff, and they don't use it. In fact, they do everything basically in the main.brs.
Going to post that below here and hope that someone, anyone, knows enough about subscription inclusion you can point out where I need to call the subscription flow:
Sub init()
m.screenBG=m.top.findNode("screenBG")
m.screenBG.color="#000000"
m.AC_Font_28= CreateObject("roSGNode","Font")
m.AC_Font_28.uri="pkg://fonts/AvenirNextBold/AvenirNext-Bold.ttf"
m.AC_Font_28.size=30
m.AC_Font_36= CreateObject("roSGNode","Font")
m.AC_Font_36.uri="pkg://fonts/AvenirNextBold/AvenirNext-Bold.ttf"
m.AC_Font_36.size=36
m.AC_Font_32= CreateObject("roSGNode","Font")
m.AC_Font_32.uri="pkg://fonts/AvenirNextBold/AvenirNext-DemiBold.ttf"
m.AC_Font_32.size=32
m.appLaunch=false
m.customOverlay=m.top.findNode("customOverlay")
m.bannerImage=m.top.findNode("bannerImage")
m.bannerTitle=m.top.findNode("bannerTitle")
m.bannerTimeStamp=m.top.findNode("bannerTimeStamp")
m.bannerDesc=m.top.findNode("bannerDesc")
m.releaseYear=m.top.findNode("releaseYear")
m.contentMetadata=m.top.FindNode("contentMetadata")' as Object
m.contentCredit=m.top.findNode("contentCredit")
m.contentGenres=m.top.findNode("contentGenres")
m.hdText=m.top.findNode("hdText")
m.viewsCount=m.top.findNode("viewsCount")
m.viewsIcon=m.top.findNode("viewsIcon")
m.contentRow=m.top.findNode("contentRow")
m.contentRow.focusXOffset=[(0)]
m.contentRow.itemSize=[(1700),(250)]
m.contentRow.translation=[(150),(600)]
m.contentRow.numRows=(10)
'm.contentRow.focusXOffset=[(200)]
m.contentRow.itemSpacing=[0,30]
m.contentRow.rowItemSpacing= [[(10),(3)]]
m.contentRow.rowLabelOffset= [(0),(17)]
m.contentRow.rowCounterRightOffset=0.10
m.contentRow.rowLabelFont=m.AC_Font_28
m.contentRow.rowLabelColor="#ffffff"
m.contentRow.ObserveField("rowItemSelected","homeContentSelection")' as Boolean
m.contentRow.ObserveField("rowItemFocused","homeContentFocused")' as Boolean
m.appLogo=m.top.findNode("appLogo")
m.appLogo.height=m.global.appLogoHeight
m.appLogo.width=m.global.appLogoWidth
m.appLogo.translation=[1920-m.global.appLogoWidth-100,1080-m.global.appLogoHeight-50]
m.videoPlayer=m.top.findNode("videoPlayer")
m.videoPlayer.ObserveField("state","onStateChangedForVideo")' as Boolean
m.videoPlayer.ObserveField("position","onVideoPositionRender")' as Boolean
m.peviousestate=""
m.adPlayToBeDone=false
m.adPlayBackInterval=0
m.top.signalBeacon("AppLaunchComplete")
end sub
Sub loadDataForUI()
getURLCallGet("https://fswnetwork.online/roku3.json","contentDataCall")
ENd Sub
SUb setFocus()
m.focusKey=0
updateFocus()
End SUb
Sub loadContentData(json As Object)
jsonData=parseJSON(json)
if jsonData<>invalid
if jsonData.tvSpecials<>invalid and jsonData.tvSpecials.Count()>0
m.container=[]
for each item in jsonData.tvSpecials
dateTime=createObject("roDateTime")
if item.releaseDate<>invalid
releaseDate=item.releaseDate+"T00:00:00+00:00"
dateTime.FromISO8601String(releaseDate)
item.AddReplace("newReleaseDate",dateTime.AsSeconds())
end if
m.container.Push(item)
end for
m.finalContainer=[]
for each item in jsonData.categories
contentData=[]
for each item2 in jsonData.playlists
if item2.name=item.playlistName
for each item3 in item2.itemIds
for each content in m.container
if item3 = content.id
contentData.Push(content)
end if
end for
end for
end if
end for
item.AddReplace("contents",contentData)
m.finalContainer.Push(item)
end for
rowItemSize=[]
rowHeights=[]
parentNode=createObject("roSGNode","ContentNode")
for each item in m.finalContainer
if item.contents.Count()>0
rowHeights.Push([250])
rowItemSize.Push([(345),(194)])
shelfNode=createObject("roSGNode","ContentNode")
shelfNode.title=Ucase(item.name)
for each item2 in item.contents
itemNode=createObject("roSGNode","CustomContentNode")
itemNode.placeHolderImage="pkg://images/demo-thumb3.png"
itemNode.thumbnailImage=item2.thumbnail
itemNode.contentTitle=item2.title
itemNode.shortDesc=item2.shortDescription
itemNode.detailContent=formatJSON(item2)
itemNode.contentReleaseYear=item2.releaseDate
itemNode.streamURL=item2.content.videos[0].url
if item2.adPlayBackonStartOfVideo<>invalid and item2.adPlayBackURL<>invalid and Lcase(type(item2.adPlayBackURL)).inStr("string")>=0
itemNode.addField("adPlayBackonStartOfVideo","bool",true)
itemNode.adPlayBackonStartOfVideo=item2.adPlayBackonStartOfVideo
itemNode.addField("adPlayBackURL","string",true)
itemNode.adPlayBackURL=item2.adPlayBackURL
itemNode.adPlayBackInterval=item2.adPlayBackInterval
else if item2.adPlayBackonStartOfVideo<>invalid and item2.adPlayBackURL<>invalid and type(item2.adPlayBackURL)="roArray"
itemNode.addField("adPlayBackonStartOfVideo","bool",true)
itemNode.adPlayBackonStartOfVideo=item2.adPlayBackonStartOfVideo
itemNode.addField("adPlayBackURL","array",true)
itemNode.adPlayBackURL=item2.adPlayBackURL
itemNode.adPlayBackInterval=item2.adPlayBackInterval
end if
shelfNode.appendChild(itemNode)
end for
parentNode.appendChild(shelfNode)
end if
end for
m.contentRow.rowItemSize=rowItemSize
m.contentRow.rowHeights=rowHeights
m.contentRow.content=parentNode
m.contentRow.visible=true
m.contentRow.focusBitmapBlendColor=m.global.focusColorHex
m.focusKey=0
updateFocus()
end if
end if
End Sub
SUb homeContentSelection()
content=m.contentRow.content.getChild(m.contentRow.rowItemSelected[0]).getChild(m.contentRow.rowItemSelected[1])
m.contentData=createObject("roSGNode","ContentNode")
m.contentData.title=content.contentTitle
'contentData.live=true
m.exactPlayerMediaSeek=0
m.contentData.url=content.streamURL
m.contentData.streamFormat="Auto"
if content.adPlayBackonStartOfVideo<>invalid and content.adPlayBackonStartOfVideo
if content.adPlayBackURL<>invalid and Lcase(type(content.adPlayBackURL)).inStr("string")>=0
m.adcontent_main=createObject("roSGNode","ContentNode")
m.adcontent_main.title=content.contentTitle
m.adcontent_main.url=content.adPlayBackURL
m.adcontent_main.streamFormat="Auto"
m.videoplayer.content=m.adcontent_main
m.videoPlayer.control="Play"
m.videoPlayer.visible=true
m.videoPlayer.EnableTrickPlay=false
m.adPlayToBeDone=true
else if content.adPlayBackURL<>invalid and type(content.adPlayBackURL)="roArray"
m.adcontent_main=createObject("roSGNode","ContentNode")
for each item in content.adPlayBackURL
adcontent=createObject("roSGNode","ContentNode")
adcontent.title=content.contentTitle
adcontent.url=item
adcontent.streamFormat="Auto"
m.adcontent_main.appendChild(adcontent)
end for
m.videoplayer.content=m.adcontent_main
m.videoplayer.contentIsPlaylist=true
m.videoPlayer.control="Play"
m.videoPlayer.visible=true
m.videoPlayer.EnableTrickPlay=false
m.adPlayToBeDone=true
end if
else
m.adPlayToBeDone=false
m.videoplayer.content=m.contentData
m.videoPlayer.control="Play"
m.videoPlayer.visible=true
m.videoPlayer.EnableTrickPlay=true
end if
if content.adPlayBackInterval<>invalid and content.adPlayBackInterval>0
m.adPlayBackInterval=content.adPlayBackInterval
end if
m.focusKey=3
updateFocus()
ENd Sub
Sub homeContentFocused()
contentData=m.contentRow.content.getChild(m.contentRow.rowItemFocused[0]).getChild(m.contentRow.rowItemFocused[1])
m.bannerImage.uri=contentData.thumbnailImage
m.bannerTitle.text=Ucase(contentData.contentTitle)
m.bannerDesc.text=contentData.shortDesc
m.releaseYear.text=contentData.contentReleaseYear
m.contentMetadata.visible=true
contentJson=parseJSON(contentData.detailContent)
m.contentGenres.text=""
genreIndex=0
if contentJson.genres<>invalid and contentJson.genres.Count()>0
for each genre in contentJson.genres
genreIndex+=1
if genreIndex=contentJson.genres.Count()
m.contentGenres.text+=genre
else
m.contentGenres.text+=genre+", "
end if
end for
end if
End Sub
Sub playLiveVideo()
if m.jsonApiData.liveStreaming<>invalid and m.jsonApiData.liveStreaming.enabled<>invalid and m.jsonApiData.liveStreaming.enabled and m.jsonApiData.liveStreaming.src<>invalid and m.jsonApiData.liveStreaming.src<>""
m.liveSection.visible=true
contentData=createObject("roSGNode","ContentNode")
contentData.title="Live"
'contentData.live=true
contentData.url=m.jsonApiData.liveStreaming.src
contentData.streamFormat="Auto"
m.videoplayer.content=contentData
m.videoPlayer.control="Play"
m.videoPlayer.visible=true
m.videoPlayer.EnableTrickPlay=false
m.videoPlayer.enableUI=true
m.focusKey=3
updateFocus()
end if
End SUb
Sub updateFocus()
if m.focusKey=0
m.videoPlayer.visible=false
m.contentRow.setFocus(true)
else if m.focusKey=3
m.videoPlayer.setFocus(true)
end if
End SUb
Sub onVideoPositionRender()
if m.adPlayBackInterval>0 AND m.adPlayToBeDone=false
if m.videoPlayer.state="playing"
if Cint(m.videoPlayer.Position)>0 and (Cint(m.videoPlayer.Position) mod m.adPlayBackInterval=0)
m.exactPlayerMediaSeek=Cint(m.videoPlayer.Position)+5
m.videoPlayer.control="Stop"
m.videoplayer.content=m.adcontent_main
m.videoplayer.contentIsPlaylist=true
m.videoPlayer.control="Play"
m.videoPlayer.visible=true
m.videoPlayer.EnableTrickPlay=false
m.adPlayToBeDone=true
end if
end if
end if
end sub
SUB onStateChangedForVideo()
print"the state of the video==>"m.videoPlayer.state
if m.videoPlayer.state="finished"
if m.adPlayToBeDone=true
?"check here"
m.adPlayToBeDone=false
m.videoplayer.content=m.contentData
m.videoPlayer.seek=m.exactPlayerMediaSeek
m.videoPlayer.control="Play"
m.videoPlayer.visible=true
m.videoPlayer.EnableTrickPlay=true
else
?"check here2"
m.videoPlayer.control="stop"
m.videoPlayer.visible=false
m.focusKey=0
updateFocus()
end if
else if m.videoPlayer.state="buffering"
else if m.videoPlayer.state="stopped"
m.videoPlayer.control="stop"
m.focusKey=2
updateFocus()
else if m.videoPlayer.state="error"
m.videoPlayer.control="stop"
m.videoPlayer.visible=false
m.focusKey=0
updateFocus()
else if m.videoPlayer.state = "paused"
else if m.videoPlayer.state = "playing" AND m.peviousestate = "paused"
m.animateOffSet=false
else if m.videoPlayer.state="playing"
else
m.videoPlayer.control="stop"
m.focusKey=0
updateFocus()
end if
ENd SUB
function onKeyEvent(key as String, press as Boolean) as Boolean
result = false
if press then
if key="back"
if m.videoPlayer.visible=true
m.videoPlayer.visible=false
m.videoPlayer.control="Stop"
m.focusKey=0
updateFocus()
result=true
end if
else if key="options"
else if key="play"
else if key="right"
if m.focusKey=1 and m.liveSection.visible
m.focuskey=2
updateFocus()
result=true
end if
else if key="left"
if m.focusKey=2
m.focuskey=1
updateFocus()
result=true
end if
else if key="down"
if m.focusKey=1 or m.focusKey=2
m.focuskey=0
updateFocus()
result=true
end if
else if key="up"
if m.focusKey=0
m.focuskey=1
updateFocus()
result=true
end if
end if
end if
return result
end function