FFMPEG streams from Docker container application are not playing on other computers
I’m building a docker container app using dotnet core that captures and plays audio streams using ffmpeg.
Since some of the URLs cannot be played directly in a web browser, audio needs to be processed by ffmpeg first. The ffmpeg output is a local url 127.0.0.1:8080 that is sent back to a browser in an Ajax call.
The audio plays perfectly in Visual Studio during development. I understand, since URL refers to localhost, there is no issue playing the audio. Unfortunately, with application being installed as docker container, the audio is being blocked. Initially, my guess was it was CORS that was blocking the stream. Also I considered the possibility that I have to use LAN IP address of the machine hosting docker container. This did not solve the problem
either.
Here is my code so far in Startup.cs
services.AddCors(options => options.AddPolicy("AllowAll",
builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
app.UseCors("AllowAll");
app.UseRouting();
Here is an Ajax call
$.ajax({
type: 'POST',
url: '/live?handler=PlayStream',
beforeSend: function (xhr) {
xhr.setRequestHeader('XSRF-TOKEN',
$('input:hidden[name="__RequestVerificationToken"]').val());
},
dataType: 'json',
data: { 'streamId': streamId },
success: function (data) {
var json = JSON.parse(data);
source = new Audio(json.InputUri);
source.play();
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
I would appreciate any suggestions how to solve this problem. Thanks
Read more here: Source link
