diff --git a/examples/torrent-dht-channels.livecodescript b/examples/torrent-dht-channels.livecodescript index 50308d2..2557044 100644 --- a/examples/torrent-dht-channels.livecodescript +++ b/examples/torrent-dht-channels.livecodescript @@ -27,9 +27,7 @@ script "dhtChannelsApp" -- channel's secret key could have published it). -- -- Click any transfer to see the files inside it with a live per-file progress --- bar (btFileList). Hit "Stream" on a video or audio release and it downloads in --- order (btSetSequentialDownload) AND plays right here in a built-in player that --- appears over the transfer pane. The transfers table shows inline progress bars. +-- bar (btFileList). The transfers table shows inline progress bars too. -- -- It also includes a "Quick drop" panel using IMMUTABLE items: pin a short text, -- get a 40-character content-address code, and fetch any code back. @@ -53,7 +51,6 @@ local sFeedKey -- array: feed-list line -> channel pubkey local sFeedMag -- array: feed-list line -> magnet local sFeedTitle -- array: feed-list line -> release title local sXferHandle -- array: transfers-list line -> torrent handle -local sHasPlayer -- "true" once the native player object built OK -- ---- lifecycle --------------------------------------------------------------- on openStack @@ -94,12 +91,6 @@ on mouseUp case "chCopyMag" chCopySelectedMagnet break - case "chStream" - chStreamSelected - break - case "chCloseStream" - chCloseStream - break case "chXfers" chShowFilesForSelection break @@ -130,7 +121,6 @@ end mouseDoubleUp -- ---- self-building UI (idempotent) ------------------------------------------- command chBuild - local tErr if there is a field "chLog" then exit chBuild end if @@ -178,10 +168,10 @@ command chBuild set the textFont of field "chXfers" to "Courier" set the textSize of field "chXferHeader" to 10 set the textSize of field "chXfers" to 10 - chMakeButton "chStream", "Stream Selected (play in order)", "596,294,820,318" - chMakeLabel "chFilesCaption", "Click a transfer to see its files. Stream plays a video/audio release here as it arrives.", "828,296,1164,318", 9 + -- 3b. Contents of the selected transfer (live per-file progress via btFileList) + chMakeLabel "chFilesCaption", "Click a transfer above to see the files inside it, with a live per-file progress bar.", "596,296,1164,318", 9 chMakeLabel "chFilesHeader", "File" & tab & "Size" & tab & "Progress", "596,322,1164,340", 10 - chMakeList "chFiles", "596,342,1164,452", true + chMakeList "chFiles", "596,342,1164,470", true set the tabStops of field "chFilesHeader" to "340,440" set the tabStops of field "chFiles" to "340,440" set the textFont of field "chFilesHeader" to "Courier" @@ -205,32 +195,6 @@ command chBuild set the textFont of field "chFetchCode" to "Courier" set the textSize of field "chMyKey" to 9 set the textSize of field "chFollowKey" to 9 - -- ===== streaming overlay: a native player shown ONLY while streaming ===== - -- Built last so it sits on TOP of the right column; hidden until Stream is used. - -- When shown it covers the transfers/files pane; Close returns to that view. - chMakeLabel "chStreamBar", "", "596,62,1080,104", 11 - set the opaque of field "chStreamBar" to true - set the backgroundColor of field "chStreamBar" to "20,24,32" - set the foregroundColor of field "chStreamBar" to "255,255,255" - set the textStyle of field "chStreamBar" to "bold" - set the visible of field "chStreamBar" to false - chMakeButton "chCloseStream", "Close", "1086,62,1164,104" - set the visible of button "chCloseStream" to false - -- the player object is optional: some OXT builds may not ship it, so build it - -- defensively and remember whether it worked (sHasPlayer gates every player op) - put false into sHasPlayer - try - if there is no player "chPlayer" then - create player - set the name of the last player to "chPlayer" - end if - set the rect of player "chPlayer" to "596,108,1164,452" - set the showController of player "chPlayer" to true - set the visible of player "chPlayer" to false - put true into sHasPlayer - catch tErr - put false into sHasPlayer - end try chAddTips unlock screen end chBuild @@ -305,8 +269,6 @@ command chAddTips set the tooltip of button "chCopyMag" to "Copy the selected file's magnet link to the clipboard." set the tooltip of button "chUnfollow" to "Stop following the selected file's channel." set the tooltip of field "chXfers" to "Click a transfer to see its files and per-file progress below." - set the tooltip of button "chStream" to "Play the selected transfer's video/audio here as it downloads in order." - set the tooltip of button "chCloseStream" to "Stop the player and return to the transfer view." set the tooltip of field "chFiles" to "Files inside the selected transfer, with live per-file progress." set the tooltip of field "chPinText" to "Type any short text (up to 1000 bytes) to pin to the network." set the tooltip of button "chPin" to "Store the text on the DHT and get back a short share code." @@ -328,8 +290,7 @@ command chHelp put tMsg & " one and Download; it transfers from them while they are online. Every entry is signed," & return into tMsg put tMsg & " so it is tamper-proof." & return & return into tMsg put tMsg & "3) TRANSFERS - a live view of what you are sending and receiving. Click one to see" & return into tMsg - put tMsg & " the files inside it with per-file progress. Stream a video or audio release and it" & return into tMsg - put tMsg & " plays right here in a built-in player while it downloads in order." & return & return into tMsg + put tMsg & " the files inside it, each with its own live per-file progress bar." & return & return into tMsg put tMsg & "4) QUICK DROP - paste any text, get a short code; anyone with the code gets it back." & return & return into tMsg put tMsg & "TRY IT on two machines: Copy your card on one, Follow it on the other, then share a file." into tMsg answer tMsg with "Got it" @@ -848,7 +809,7 @@ command chRefreshTransfers chShowFiles tSelH end chRefreshTransfers --- ---- selected-transfer detail: the file table + streaming -------------------- +-- ---- selected-transfer detail: the file table (btFileList) ------------------- -- The 0-based line of the selected transfer, or 0 if none. function chSelectedXferLine @@ -910,129 +871,6 @@ command chShowFilesForSelection chShowFiles chSelectedXferHandle() end chShowFilesForSelection --- Stream the selected transfer: turn on sequential (in-order) download so the --- file fills from the front, then point the built-in player at the largest --- video/audio file inside it and play. The player overlays the transfer pane. -command chStreamSelected - local tH, tR, tRel, tKind, tStatus, tSave, tPath, tName - put chSelectedXferHandle() into tH - if tH is 0 then - chLog "Select a transfer first, then click Stream." - exit chStreamSelected - end if - -- in-order download so a media file is watchable/listenable as it arrives - put btSetSequentialDownload(tH, true) into tR - if tR is not 0 then - chLog "Could not enable streaming:" && btLastError() - exit chStreamSelected - end if - -- find the main video/audio file (those are the only two we stream) - put chMainMediaFile(tH) into tRel - if tRel is "" then - chLog "Streaming on (in order). No video or audio file in this transfer to play." - exit chStreamSelected - end if - put chMediaKind(tRel) into tKind - if not sHasPlayer then - chLog "Streaming on (in order):" && tRel & ". (No player in this build - open it in your media app.)" - exit chStreamSelected - end if - -- build the on-disk path: the torrent's save path + the file's relative path - put btTorrentStatus(tH) into tStatus - put tStatus["savePath"] into tSave - if tSave is empty then - chLog "Streaming on (in order). Waiting for a download location to appear..." - exit chStreamSelected - end if - put tSave & "/" & tRel into tPath - replace "\" with "/" in tPath - if there is no file tPath then - chLog "Streaming in order - '" & tRel & "' is not on disk yet. Click Stream again in a moment to play." - exit chStreamSelected - end if - put chTrunc(tRel, 56) into tName - chOpenPlayer tPath, tName, tKind -end chStreamSelected - --- Point the player at a file, reveal the overlay, and start playback. Wrapped --- defensively because player capabilities vary across OXT builds/platforms. -command chOpenPlayer pFullPath, pTitle, pKind - local tErr - if not sHasPlayer then - exit chOpenPlayer - end if - try - set the filename of player "chPlayer" to pFullPath - put " Streaming (" & pKind & "): " & pTitle into field "chStreamBar" - set the visible of field "chStreamBar" to true - set the visible of button "chCloseStream" to true - set the visible of player "chPlayer" to true - set the showController of player "chPlayer" to true - start player "chPlayer" - chLog "Playing '" & pTitle & "' (" & pKind & ") - it streams as the download fills in order." - catch tErr - chLog "Could not open the player:" && tErr - end try -end chOpenPlayer - --- Stop playback and hide the overlay, returning to the transfer/files view. -command chCloseStream - local tErr - if not sHasPlayer then - exit chCloseStream - end if - try - stop player "chPlayer" - set the filename of player "chPlayer" to empty - catch tErr - end try - set the visible of player "chPlayer" to false - set the visible of field "chStreamBar" to false - set the visible of button "chCloseStream" to false -end chCloseStream - --- Classify a path as "video", "audio", or "" by its file extension. Video and --- audio are the only kinds the player streams. -function chMediaKind pPath - local tSuffix, tVideo, tAudio - set the itemDelimiter to "." - if the number of items of pPath < 2 then - return "" - end if - put toLower(the last item of pPath) into tSuffix - put "mp4,m4v,mov,mkv,avi,webm,mpg,mpeg,wmv,flv,3gp,ogv" into tVideo - put "mp3,m4a,aac,flac,wav,ogg,oga,opus,wma,aiff,aif" into tAudio - set the itemDelimiter to comma - if tSuffix is among the items of tVideo then - return "video" - end if - if tSuffix is among the items of tAudio then - return "audio" - end if - return "" -end chMediaKind - --- The relative path of the LARGEST video/audio file in a torrent (a release is --- usually one media file plus small extras), or "" if it holds no media. -function chMainMediaFile pHandle - local tFiles, tFile, tBest, tBestSize - if pHandle is 0 or pHandle is empty then - return "" - end if - put btFileList(pHandle) into tFiles - put "" into tBest - put -1 into tBestSize - repeat for each element tFile in tFiles - if chMediaKind(tFile["path"]) is not "" then - if tFile["size"] > tBestSize then - put tFile["size"] into tBestSize - put tFile["path"] into tBest - end if - end if - end repeat - return tBest -end chMainMediaFile - -- a 10-segment ASCII progress bar, e.g. [####------] 42% (monospaced fields) function chProgressBar pPct local tFilled