[ ]   [ ]   [ ]                        [ ]      [ ]   [ ]

Oldest Rock song on RP - oldviolin - Mar 28, 2024 - 2:02pm
 
Breaking News - Proclivities - Mar 28, 2024 - 2:00pm
 
Photos you have taken of your walks or hikes. - NoEnzLefttoSplit - Mar 28, 2024 - 12:21pm
 
Irony 101 - MrDill - Mar 28, 2024 - 12:21pm
 
Photography Forum - Your Own Photos - MrDill - Mar 28, 2024 - 12:15pm
 
RP automation with iOS Shortcuts App - pradler4kant - Mar 28, 2024 - 11:57am
 
Lyrics that strike a chord today... - newwavegurly - Mar 28, 2024 - 11:48am
 
Baseball, anyone? - ScottFromWyoming - Mar 28, 2024 - 11:46am
 
The Obituary Page - ScottFromWyoming - Mar 28, 2024 - 11:31am
 
Talk Behind Their Backs Forum - VV - Mar 28, 2024 - 11:27am
 
March 2024 Photo Theme - Many - NoEnzLefttoSplit - Mar 28, 2024 - 11:07am
 
Wordle - daily game - rgio - Mar 28, 2024 - 11:00am
 
Ukraine - Beaker - Mar 28, 2024 - 9:41am
 
Bug Reports & Feature Requests - Beaker - Mar 28, 2024 - 9:30am
 
NY Times Strands - geoff_morphini - Mar 28, 2024 - 8:37am
 
NYTimes Connections - geoff_morphini - Mar 28, 2024 - 8:29am
 
Radio Paradise Comments - pilgrim - Mar 28, 2024 - 8:19am
 
Business as Usual - black321 - Mar 28, 2024 - 8:09am
 
• • • The Once-a-Day • • •  - black321 - Mar 28, 2024 - 7:44am
 
Trump - rgio - Mar 28, 2024 - 7:29am
 
Outstanding Covers - thisbody - Mar 28, 2024 - 5:51am
 
Today in History - DaveInSaoMiguel - Mar 28, 2024 - 4:28am
 
USA! USA! USA! - R_P - Mar 27, 2024 - 7:40pm
 
Little known information...maybe even facts - haresfur - Mar 27, 2024 - 6:21pm
 
Live Music - oldviolin - Mar 27, 2024 - 5:08pm
 
RightWingNutZ - R_P - Mar 27, 2024 - 3:48pm
 
Please Don't Post Here - Red_Dragon - Mar 27, 2024 - 11:02am
 
Motivational Office Cliches... - NoEnzLefttoSplit - Mar 26, 2024 - 10:20pm
 
(Big) Media Watch - Red_Dragon - Mar 26, 2024 - 6:18pm
 
YouTube: Music-Videos - miamizsun - Mar 26, 2024 - 4:10pm
 
Israel - R_P - Mar 26, 2024 - 12:24pm
 
Solar / Wind / Geothermal / Efficiency Energy - islander - Mar 26, 2024 - 8:00am
 
Is there any DOG news out there? - Beez - Mar 26, 2024 - 7:24am
 
Food - Steely_D - Mar 26, 2024 - 1:41am
 
Vinyl Only Spin List - kurtster - Mar 25, 2024 - 6:56pm
 
Derplahoma! - Red_Dragon - Mar 25, 2024 - 3:48pm
 
Frequent drop outs (The Netherlands) - kingen - Mar 25, 2024 - 2:43pm
 
China - R_P - Mar 25, 2024 - 11:59am
 
Musky Mythology - R_P - Mar 25, 2024 - 11:20am
 
Play history seems to indicate that I"m streaming 24/7, b... - jarro - Mar 25, 2024 - 10:44am
 
April 8th Partial Solar Eclipse - Coaxial - Mar 24, 2024 - 6:22pm
 
New Music - KurtfromLaQuinta - Mar 24, 2024 - 5:07pm
 
Dental Floss Tycoons, and other Montana Myths, Facts, and... - Red_Dragon - Mar 24, 2024 - 12:32pm
 
Orbiting Earth - oldviolin - Mar 24, 2024 - 9:42am
 
Basketball - oldviolin - Mar 23, 2024 - 2:50pm
 
What Makes You Laugh? - ScottFromWyoming - Mar 23, 2024 - 1:54pm
 
Joe Biden - kurtster - Mar 23, 2024 - 11:17am
 
Technical Streaming Note for Nerdy RP DIYers - sjagminas1 - Mar 23, 2024 - 10:16am
 
Museum Of Bad Album Covers - Proclivities - Mar 23, 2024 - 8:56am
 
Other Medical Stuff - Antigone - Mar 22, 2024 - 3:06pm
 
Country Up The Bumpkin - oldviolin - Mar 22, 2024 - 11:06am
 
Pernicious Pious Proclivities Particularized Prodigiously - Red_Dragon - Mar 22, 2024 - 9:17am
 
Memorials - Remembering Our Loved Ones - Bill_J - Mar 21, 2024 - 8:54pm
 
Can you afford to retire? - DaveInSaoMiguel - Mar 21, 2024 - 2:15pm
 
Mixtape Culture Club - KurtfromLaQuinta - Mar 21, 2024 - 11:10am
 
What Did You See Today? - KurtfromLaQuinta - Mar 20, 2024 - 5:13pm
 
Annoying stuff. not things that piss you off, just annoyi... - ScottFromWyoming - Mar 20, 2024 - 4:31pm
 
Upcoming concerts or shows you can't wait to see - Antigone - Mar 20, 2024 - 3:10pm
 
Russia - NoEnzLefttoSplit - Mar 20, 2024 - 11:44am
 
2024 Elections! - Lazy8 - Mar 20, 2024 - 7:26am
 
Economix - R_P - Mar 19, 2024 - 4:36pm
 
Name My Band - DaveInSaoMiguel - Mar 19, 2024 - 10:53am
 
Delicacies: a..k.a.. the Gross Food forum - DaveInSaoMiguel - Mar 19, 2024 - 10:12am
 
New Forum Member on "What Makes RP Great" - miamizsun - Mar 19, 2024 - 4:38am
 
Cache stopped working on old Android Phone - Eisenwindel - Mar 19, 2024 - 1:50am
 
Cryptic Posts - Leave Them Guessing - Bill_J - Mar 18, 2024 - 8:23pm
 
Damn Dinosaurs! - oldviolin - Mar 18, 2024 - 8:16pm
 
One Partying State - Wyoming News - geoff_morphini - Mar 18, 2024 - 3:58pm
 
Great guitar faces - skyguy - Mar 18, 2024 - 3:33pm
 
Despots, dictators and war criminals - R_P - Mar 18, 2024 - 12:41pm
 
Uploading Music - dischuckin - Mar 18, 2024 - 11:55am
 
Media Matters - thisbody - Mar 18, 2024 - 10:03am
 
NASA & other news from space - miamizsun - Mar 18, 2024 - 4:13am
 
MEALTICKET - drinpt - Mar 17, 2024 - 4:13am
 
What makes you smile? - Steely_D - Mar 16, 2024 - 7:31pm
 
Index » Radio Paradise/General » General Discussion » RP Now Playing Widget for iOS Page:
Post to this Topic
Diamar

Diamar Avatar

Location: Orcas Island, WA
Gender: Male


Posted: Jan 27, 2022 - 12:14pm

I’ve been using Scriptable to display a “Now Playing” widget for RP on iOS. I cobbled it together from some random code bits I picked up from the web, then customized it. It lets you see the album covers and song title/artist for the currently playing song on any RP channel.

To use it:
  1. Install the Scriptable app on your iOS device if it’s not there already
  2. Launch the Scriptable app, then create and save a new script using the code at the end of this post
  3. Create a new widget (or widget stack) on your iOS device, choosing “Scriptable” as the type and any of the Run Script widgets it can make
  4. Specify the newly-made script from step 2 above, adding the parameter for the channel you’d like the widget to display (main, mellow, rock, world). If you don’t add a parameter, “main” will default
If you put 4 calls to your widget in a widget stack, you can just scroll through all the channels and see covers.

The only thing I can’t control is how quickly the screen updates, since iOS doesn’t apparently let you have too much control over that. But it’ll always refresh if you tap it (but it launches the Scriptable app to show it). 

Here’s the code:
let stationName = "main"
let stationID = 0
stationId = getConfiguredStationId()
let nowPlaying = await loadNowPlaying(stationId)
let widget = await createWidget(nowPlaying, stationName)

if (config.runsInWidget) {
Script.setWidget(widget)
Script.complete()
} else await widget.presentLarge()

async function createWidget(nowPlaying,stationName) {

let widget = new ListWidget()
widget.setPadding(8, 10, 12, 10)

// set gradient background with transparency
let gradient = new LinearGradient()
gradient.colors =
gradient.locations = <0.0, 1>
widget.backgroundGradient = gradient
widget.backgroundColor = new Color("#1c1c1c")

// load image
let coverArt = await loadImage(nowPlaying.cover)
widget.backgroundImage = coverArt

//Set refresh time unless this song is almost over
//Only mess with this if we have more than "enough" seconds left
const enough = 4
if (nowPlaying.time > enough) {
const n = new Date(Date.now())
widget.refreshAfterDate = new Date((Number(n) + 1000 * Math.max(1, nowPlaying.time-enough)))
} else widget.refreshAfterDate = null


widget.addSpacer()

//add channel
let channelTxt = widget.addText("RP " + stationName)
channelTxt.font = Font.semiboldRoundedSystemFont(12)
channelTxt.textColor = Color.red()

// add title and artist
let titleTxt = widget.addText(nowPlaying.title)
titleTxt.font = Font.boldRoundedSystemFont(15)
titleTxt.textColor = Color.white()
widget.addSpacer(2)

let artistTxt = widget.addText(nowPlaying.artist)
artistTxt.font = Font.boldRoundedSystemFont(14)
artistTxt.textColor = Color.yellow()
//widget.url = "vlc-x-callback://x-callback-url/stream?url=https://stream.radioparadise.com/" + stationName

return widget

}

// verify the configured flac stream
function getConfiguredStationId() {
let param = args.widgetParameter
let stationID
//if(param != null) {
switch (param) {
case 'main':
stationId = 0
stationName = "Main"
break
case 'mellow':
stationId = 1
stationName = "Mellow"
break
case 'rock':
stationId = 2
stationName = "Rock"
break
case 'world':
stationId = 3
stationName = "World"
break
default:
stationId = 0
stationName = "Main"
}
return stationId
}

// helper function to load and parse a restful json api
async function loadNowPlaying(stationId) {
const url = "https://api.radioparadise.com/api/now_playing?chan=" + stationId
let req = new Request(url)
let json = await req.loadJSON()
return json
}

// helper function to download an image from a given url
async function loadImage(imgUrl) {
let req = new Request(imgUrl)
let image = await req.loadImage()
return image
}


Page: