Conditional Transclude to Support Audio on Desktop and Android Phone

Hi

Happy New Year!

I am trying to conditionally transclude tiddlerA if I am on desktop and tiddlerB if I am on my Android phone

I use RCX on Android to get around the security measures that prevent locally stored webpages including locally stored content (video / audio ) the consequence is that content is served up on http://127.0.0.1:8080 if I am on android which can then be accessed.

If I am on Desktop then video and audio content lie in a subdirectory on local disk one level lower than my main tiddlywiki file.

My existing solution for video (which I was helped with) uses two approaches

  1. the poster image for the video thumbnail uses a conditional which detects the tell-tale http://127.0.0.1:8080 if RCX is being used and hence I am on Android.

  2. The source for the video simply uses the HTML drop through which makes life a lot simpler as it selects the first video URI it can find and play.

<html><video width='80%'  controls preload='none'

poster={{{ [{$:/info/url/protocol}prefix[content]then[http://127.0.0.1:8080/videos/example.jpg]]:else[[videos/example.jpg]] }}}

>
<source src='http://127.0.0.1:8080/videos/example.webm'>
<source src='videos/example.webm'>
    Your browser does not support the HTML 5 video tag.
</video></html>

My approach to audio was to create two tiddlers of type audio/mp3 differing only in the additional http://127.0.0.1:8080/ prefix in the URI for the tiddler intended for android.

The stage I am at now is that I have tiddler intended to transclude one of the following tiddlers.

{{TiddlerDesktop}}

{{TiddlerAndroid}}

I just have not yet figured out how to show the appropriate one… in psuedo code it would be something like…

if $:/info/url/protocol}prefix[content]
then
{{TiddlerAndroid}}
else
{{TiddlerDesktop}}

So only one tiddler would be transcluded - although pseudo code the conditional indicated after the ‘if’ works fine - I just need to be able to use it in a manner that works with the conditional transclusions that I have tried to indicate in pseudo code.

Thanks

1 Like

Happy new year!

You could use a filter similar to used by you in the poster of the video in a transclude widget. For example something like the following example:

<$transclude tiddler={{{ [{$:/info/url/protocol}prefix[content]then[TiddlerAndroid]else[TiddlerDesktop] }}} />

(I didn’t test it, but it could work)

Thanks for the suggestion Alvaro unfortunately it does not work.

The filter expression has an error in its end, a lost bracket

else[TiddlerDesktop]

to

else[TiddlerDesktop]]
1 Like

Thanks Alvaro - it’s working now.