Rails Active Storage : video_tag not showing video - ruby

I m trying to implement some upload then play video in my app using Rails 5.2.3 and Active Storage. After fighting with active storage for a while i m finally sure that my attachment is containing the file i want to attach => after inspecting the src is correct
The problem here is that i keep getting those warnings from firefox console :
HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHM…JibG9iX2lkIn19--a44730f58a07282f626737b6a541d57fa9dc11c4/vid failed. 23
Cannot play media. No decoders for requested formats: text/html
and a video area with the following message "
No video with supported format and MIME type found"
Now, the console warnings are only showing up in Firefox but the video isn't playable in all the browsers that i tested so i think that my problem got something to do with the warning. I m new to rails so i ve tried all what i have found in google without solving my problem.
I m showing the video with the video_tag this way :
<%= video_tag(url_for(#play.clip), style: "width:100%;height:auto", :controls => true) if #play.clip.attached? %>
And added a meme_types.rb in initializers with the following code
Rack::Mime::MIME_TYPES.merge!({
".mp4" => "video/mp4",
})
I have tried to display the video using plain html5 ( which is the same) and i m naturally getting the same warnings...

fixed. The issue wasn't coming from the active storage itself. The get request to play the video was stopped by a line i wrote in routes.rb to make all "unknown routes" redirect to root_path :
get '*path' => redirect('/')
Now t hat the video playing video has been fixed i have to deal with "redirecting unknown paths to root without causing a problem with the GET "

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

serve video with go gin

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).

Ruby-Watir Warning - Selenium::WebDriver::Error::ObsoleteElementError

Hey y'all I'm getting a warning running my watir test automation code and even though it works I want to address it.
The Warning: 2020-02-12 08:35:47 WARN Selenium [DEPRECATION]
Selenium::WebDriver::Error::ObsoleteElementError is deprecated. Use
Selenium::WebDriver::Error::StaleElementReferenceError (ensure the
driver supports W3C WebDriver specification) instead.
The offending line of code:
iframe.select(:id => 'col0').wait_until(&:present?)
from this larger snippet.
iframe = #b.iframe(:title => /Mass Delete/)
iframe.wait_until(&:present?)
if iframe.present?
iframe.link(:visible_text => /Mass Delete #{type}/).click
iframe.select(:id => 'col0').wait_until(&:present?)
iframe.option(:text => /Owner Alias/).select
iframe.option(:text => 'equals').select
iframe.text_field(:id => "fval0").set user
iframe.button(:title => "Search").click
else
raise "Unable to locate the Salesforce Iframe"
end
Here's the page html:
Page Html
I've tried using different locators to interact with that element but to no avail.
This will be addressed in the next version of Watir - exact release date is TBD. In the short-term, you have a couple of options to hide the warning.
Log to File
I would suggest sending the Selenium logs to a file. This keeps it separated and still available if you happen to need it.
Selenium::WebDriver.logger.output = 'selenium.log'
Ignore Warnings
Usually you do not need the Selenium warnings as they should get addressed by Watir changes. Therefore you could change the Selenium logger to ignore warnings:
Selenium::WebDriver.logger.level = :error

How to upload video to YouTube via Ruby?

I need to upload video files from my computer to youtube automatically, I use ruby.
I tried gem youtube_it - I have error YouTubeIt::AuthenticationError: BadAuthentication - my actions:
client = YouTubeIt::Client.new(:username => "email#gmail.com", :password => "my_passwd", :dev_key => "developer_key")
client.video_upload(File.open("file_from_drive"), :title => "test",:description => 'test')
Also I tested manually upload video from my email#gmail.com my_passwd Google account - I works well. Dev_key I got here - http://code.google.com/apis/youtube/dashboard
Then I tried gem gdata as here - How to upload video on YouTube with Ruby
require 'gdata'
yt = GData::Client::YouTube.new
yt.clientlogin("email#gmail.com", "my_passwd")
It raises error
GData::Client::AuthorizationError: request error 403: Error=BadAuthentication
Info=WebLoginRequired
So, How should I automatically upload video? Maybe problem is in my google account?

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.

Resources