serve video with go gin - go

I am writing a api server for upload and serve video and image by go-gin framework. I have uploaded my video to another host, and it worked
router := gin.Default()
//config := cors.DefaultConfig()
//config.AllowAllOrigins = true
routerConfig := cors.Config{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"X-Requested-With", "Authorization", "Origin", "Content-Length", "Content-Type"},
AllowCredentials: false,
MaxAge: 12 * time.Hour,
}
router.Use(cors.New(routerConfig))
router.StaticFS("/public", http.Dir("static"))
err := router.Run(":5000")
if err != nil {
panic(err)
}
When I try to access http://localhost:5000/public/{image_url}.png by chromium. It loads to browser. But when I access http://localhost:5000/public/{video_url}.mp4 by chromium, it can't load anything from browser (It can't receive)
Can someone explain for me what I am doing wrong?
Update:
Maybe I missed this content:
Here are my 2 http packages when I call a GET request

There are 2 possible explanation for your problem.
It's not a problem because your browser doesn't have any feature to run video.
(This is more possible explanation) You don't set the correct header for streaming video so the browser can't recognize or don't know what to do with that URL.
For example I get from this video, when you check the Response Header, it should show
content-length: 1570024
content-range: bytes 0-1570023/1570024
content-type: video/mp4
My suggestion is use http.ServeFile which supports serving Range requests. See related questions, GoLang http webserver provide video (mp4) and How to serve http partial content with Go?.
Updated
After checking Gin StaticFS Godoc, I don't think it support Range header.
After Test
So I have try your code and I'm wrong, Gin StaticFS can serve content range like video.
Here my screenshot, have tested it using Chromium and it works well:
And my conclusions: There is a problem with your Chromium or your codecs or your video codecs not supported on your OS (I don't know what is your OS), check this MP4 not playing on Chrome version 27.0:
due to Chrome removing support for h264, on some machines, mp4 videos encoded with it will either not work (throwing an Parser error when viewing under Firebug/Network tab - consistent with issue submitted here), or crash the browser, depending upon the encoding settings
it isn't consistent - it entirely depends upon the codecs installed on the computer - while I didn't encounter this issue on my machine, we did have one in the office where the issue occurred (and thus we used this one for testing)
it might to do with Quicktime / divX settings (the machine in question had an older version of Quicktime than my native one - we didn't want to loose our testing pc though, so we didn't update it).

Related

RecordRTC - Playing recordings on Safari fails

I am using RecordRTC to allow my application user to record their video and upload. This works perfectly fine with Chrome and Mozila Firefox but Safari having trouble playing recorded videos.
I research for the same and found mimeType: 'video/webm\;codecs=vp8' to be used for safari. However this still won't work on Safari browsers. (mac OS x and iOS)
Can someone please help me with this? I have multiple users working on different operating systems and working on different browsers and I want to make sure RecordRTC works for all of them.
I am open to change/ switch to any other alternative if available to implement this feature with cross-browser support of course.
I found Twilio but I am not sure whether Twilio supports standalone recordings or not? I mean I just want single user to go on a page record a video and upload.
Please see below my RecordRTC configuration if it helps:
const options = {
type: 'video',
mimeType: 'video/webm\;codecs=vp8',
bitsPerSecond: 128000,
timeSlice: 1000
};
After user completes the recording, I am converting it to a blob and append it to the formData to save it to the server:
var recordedBlob: Blob = recordRTC.getBlob();
formData.append('files', recordedBlob, this.courseComponent?.courseComponent?.name + '.webm');
This recorded video plays fine in Chrome and Firefox but in Safari it Fails.
Please if you can guide me through this it will be great help to me.
Thanks.
Below are the console log snaps:
1.browser does not support media recorder api
when tried to play the recorded video
says browser does not support media recorder api and try using whammyRecorder

Intercepting responses to a process in golang

I have a process that activates a browser, which makes a request to a local server.
The server should respond but I do not know how to see, client side, the answer.
I need that is the browser that makes the request. I do not want to write it myself with http.NewRequest.
client.go:
func openChrome() {
var page = "https://localhost:1333/"
program := "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
url := []string{"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", page}
attr := &os.ProcAttr{
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
}
proc,err:=os.StartProcess(program, url, attr)
proc.Wait();
// if err!=nil, log.Fatal(err)
}
To see the response and have easier control over requests could use a tool like chromedp, chromedriver (with webdriver) or selenium to load pages and find the response in the browser. All of these should be accessible to varying degrees from go, and can be used to drive the browser to go through the standard request cycle as if a human were doing it (to load content and query what is loaded).
You can see the stdout and stderr from a process you launch but that is unlikely to help you for this particular task so I'm ignoring that.
You don't give a reason for excluding a direct request, but for full control this would be another possibility, and unless you need to render html your code can do everything a browser could do (change user agent, parse html etc).

Setting contentType on AudioStreamer

I use the AudioPlayer to stream both mp3 and AAC Shoutcast streams on iOS, and in the main it works just fine. However to get AAC to work with a URL that does not end in .aac I had to hack the AudioStreamerCUR.m Objective-C code. I am not an Objective-C programmer and this was done very much on a trial and error basis. As there are number of url schemes used by Shoutcast and Icecast, my hacks are messy and it would be a lot easier to simply send the content-type along with the url like this:
var player = Titanium.Media.createAudioPlayer({
allowsAirPlay: true,
url: myURL,
contentType: "aac"
})
But I can't work out how to get a new property into the AudioPlayer proxy and then across to the actual AudioStreamerCUR.m - it seems some black magic is required. I wonder if there are any magicians who could point me in the right direction?
Thanks.
This is a property currently not exposed though the Titanium AudioPlayer API.
You might want to do a Feature Request Appcelerator JIRA. Check if it has already been requested before you create a new ticket. Refer to this question and also link back to the ticket here so that others can watch it with you.

Streaming MP3 audio to HTML5 audio tag from servlet

I'm having some cross-browser compatibility joys. I have a Ruby WEBrick server with a couple of servlets, one of which is used to stream media (Ogg and MP3). The servlet gets a couple of query parameters (a base64 urlsafe string key, a small string user, and a small number, sid). When I put the URL verbatim into Chrome, I get the QuickTime extension, and it works. When I post the same into FireFox, I get the expected unsupported codec. When I put it in Safari, it works. However, the URL is not being accessed directly. I have a jQuery Mobile app that uses the Javascript Buzz library, and uses these servlet streaming URLs as sources. The code works in Safari, allowing me to play the sounds. On FireFox, instead of falling back onto Ogg, it gives unsupported errors, and on Chrome, it does nothing. Here's the code that serves the MP3:
res.status = 200
str = File.new("Music/#{req.query['sid']}.mp3", 'r:BINARY:BINARY').read
res.body = str
res['content-type'] = 'audio/mpeg'
Can anyone tell me how to get audio streaming to all browsers through a Ruby servlet?
Note: This is not a duplicate. I've been thorough a lot of SO answers, but none work because they are designed for static files, not servlets.

Can't download from youtube encoding error

it's a week that I'm trying to write a program that download correctly from youtube
a video
the problem is this:
I've done via httpwebrequest a simple downloader and all work well.
I've tried download a mp4 video from a local server (uniform server) and all goes well, video is the same, work and is valid mp4.
When I download the same video from youtube something strange happens:
It fill some characters in downloaded file with sequence EF BF BD
for example when encounter character E2 (I've compared the two files one from youtube and the original). Googling around I discover that a server return this kinda sequence when encounterd a invalid char for your encoding, now I'm on wp7 and I can't set
Accept-Charset:
ISO-8859-1,utf-8;q=0.7,*;q=0.7
here's others useful data: I've try with these:
_webRequest.Method = "GET"; //also POST
_webRequest.UserAgent = #"Mozilla/5.0 (Windows; U; Windows NT 6.1; it; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16";
_webRequest.Accept = #"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_webRequest.BeginGetResponse(_onDownload, userState);
format url from youtube
Any Idea?
thanks
Can you set the header using the _webRequest.Headers method? See these related questions:
Cannot set some HTTP headers when using System.Net.WebRequest
Constructing a POST in C#

Resources