How to use a redirected url as the source for <img>, <audio> or <video>? - node.js

I have some media files hosted on AWS S3. I want to set up a redirect from my own website to the files, and use the url link from my own website as src for the media player, so that I can better track the number of requests for the files from my own site.
In other words, instead of using
<audio style="width: 100%;" controls="controls">
<source src="https://s3.amazonaws.com/mybucket/audiofile.mp3“ />
</audio>
I want to use
<audio style="width: 100%;" controls="controls">
<source src="https://my_own_website.com/tracks/audiofile.mp3“ />
</audio>
and have it point to https://s3.amazonaws.com/mybucket/audiofile.mp3 and play the file.
What I have tried:
Redirect on my front end (using react and react-router). I tried setting up a redirect route like so:
<Route exact={true} path="/tracks/:id" component={(props) => {
const id = props.match.params.id;
window.location.replace(`https://s3.amazonaws.com/soundwiseinc/soundcasts/${id}`);
}} />
Redirect on my back end (using node.js and express). I tried to redirect like the following:
app.get('/tracks/:id', (request, response) => {
const path = String(request.path).slice(8);
console.log('path: ', path);
response.redirect(200, https://s3.amazonaws.com/mybucket/${path});
});
But neither of them worked. The mp3 wouldn't play. And the console error says the source is not valid.

Create a server side page for ex: playmedia.php & pass the cloud file name to that page.
Add your tracking code in the page & save analytics data to database.
Stream MP3 from S3 using Amazon S3 Stream Wrapper from playmedia.php

Related

How can I show a youtube video in ejs

I am developing a web app to show a youtube video. The app is being developed with node.js and express . So I want to show the video in the html which is write as ejs.
The code looks like:
<li>
<video controls="true" src="<%= problem.solution %>" autoplay="none" preload="auto" width="600" height="400">
</video>
</li>
But it did not play at all, can any one give me some ideas? Or some materials about how to figure it out?
<iframe width="1020" height="815" src= <%= g.url %> ></iframe>
this is what I used, and it worked as the link for the video, you need to use the embed link to video.
To get the embed link, you press the share button, and there you could get a example of a iframe example with a working link.

Why is my download link requiring control click to download?

I am running a pretty basic node.js server to host a site, and all of a sudden this week one of my download links started to just redirect to the index.html page instead of downloading the pdf it points to if you just click on the file. a control+click will download the file, but that is not normal behavior from what I understand with chrome.
The button is generated as so:
<button type="button" name="button">
<a href="../images/a-manill-resume.pdf" download>Downloadable Resume</a>
</button>
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
Try setting the download attribute
<button type="button" name="button"><a download="../images/a-manill-resume.pdf">Downloadable Resume</a></button>

Orchard CMS render media public URL for path in theme razor template

Looking to add a theme setting for a site logo URL to render in the header. However, when using Azure blob storage for images, the URL is not relative and will need to ask the media library for the public URL.
Just wondering what the best way to do this is from the shape template for my header / branding?
Currently is only working with file system media storage:
<a class="logo" href="#Href("~/")">
<img width="103" height="39" alt="" src="#Href(settings.SiteLogoUrl)" >
</a>
Prefer to sore only a relative path in the setting so that any changes to public URL of the Auzre blob storage wont break the site.
Found a solution that works. In the view you can resolve the storage provider, and then use that to get the public URL
#{
var storageProvider = WorkContext.Resolve<IStorageProvider>();
}
<a class="logo" href="#Href("~/")">
<img width="103" height="39" alt="" src="#Href(storageProvider.GetPublicUrl(settings.SiteLogoUrl))" >
</a>

Kentico Media Library Relative URL

We have a Kentico project where we're using Azure Blob Storage for our media storage. When selecting a media file in a page, it stores the URL like this: www.ourhost.net/blobcontainer/kenticosite/media/medialibrary/picture.jpg
We are also using ImageProcessor.org. This only works when the image is requested through the host itself, so we need the media library selector to store the absolute URL like this: /blobcontainer/kenticosite/media/medialibrary/picture.jpg
How can this be done?
Thanks in advance. Nicolas.
I assume you are talking about Media selection form control, is that correct?
In this case the solution is for you to remove the protocol/domain from the absolute URL which is stored by the form control. You can do this by creating Custom macro since you are using Portal engine macros.
The purpose of the macro will simply be to take the absolute URL and make it a relative URL.
Instead of using this:
<img src="{% CurrentDocument["HeaderImage"] #%}" alt="{% CurrentDocument["Title"] #%}" />
You would call it like:
<img src="{% MyMacros.GetRelativeUrl(CurrentDocument["HeaderImage"]) #%}" alt="{% CurrentDocument["Title"] #%}" />
As you can see I'm using "MyMacros" namespace which is a best practise as it will enable you to keep all your macros organized. You can create custom namespaces as per this article

Is it possible to access an Azure Media Services DASH streaming URL from a secure website?

I have published a video to Azure Media Services and I am trying to open that video on an SSL-enabled website using the new Azure Media Player.
I have added a video tag to my page as per the documentation, i.e:
<video id="vid1" class="azuremediaplayer amp-default-skin" controls width="640" height="400" poster="poster.jpg" data-setup='{"logo": { "enabled": false}, "nativeControlsForTouch": false}'>
<source src="http://example.origin.mediaservices.windows.net/.../example.ism/manifest" type="application/vnd.ms-sstr+xml" />
<p class="amp-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
</p>
</video>
However when I load the page Chrome and Firefox throw a Mixed Content error:
I believe this is due to the DASH url that is generated and processed by Azure Media Player. I can get the video to load and play if I change the video tag to the following:
<video id="vid1" class="azuremediaplayer amp-default-skin" controls width="640" height="400" poster="poster.jpg" data-setup='{"logo": { "enabled": false}, "nativeControlsForTouch": false}'>
<source src="http://example.origin.mediaservices.windows.net/.../example.ism/manifest" type="application/vnd.ms-sstr+xml" data-setup='{"streamingFormats": ["SMOOTH", "HLS-V3", "HLS-V4"] }' />
<p class="amp-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
</p>
</video>
However this seems to force Azure Media Player into using Flash and the user experience is not all that great (slow to load, jumpy playback, etc).
Is it possible to stream a video that is hosted in Azure Media Services via a DASH streaming url to a secure website using Azure Media Player?
It turns out that streaming endpoints that were created before September 11, 2014 do not support streaming over ssl, however streaming endpoints that were created on or after September 11, 2014 do support streaming over ssl.
The streaming endpoint I was using was created at the start of 2014 and therefore did not support ssl. The solution was to create a new streaming endpoint and use its publish url instead.
Be aware that if you need to create a new streaming endpoint like I did you will probably want to turn off your old endpoint and remove the streaming units associated with it so you don't incur unnecessary costs.

Resources