Is there a way to cast youtube videos inside my application? - android

I'm using the "TheMovieDB" API to get information about movies, and it is possible to retrieve video information for a certain movie, like this:
videos: {
results: [
{
id: "533ec6a5c3a3685448005327",
iso_639_1: "en",
key: "ac7KhViaVqc",
name: "First Trailer",
site: "YouTube",
size: 720,
type: "Trailer"
}
]
}
As you can see, it is possible to build the youtube video url with the key provided in the JSON.
When building the MediaInfo object, you can pass the video URL, like this:
MediaInfo.Builder(MOVIE_URL)
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType("video/mp4")
.setMetadata(movieMetadata)
.build();
However, if MOVIE_URL is the youtube url, I can't cast the content.
Is it possible to cast youtube videos from my app? If yes, how can I do it?
Thanks!

There are currently no APIs in the cast SDK to accomplish that. People have had different degrees of luck with using the embedded youtube iframe approach, but that is not a perfect solution for various reasons; for example you cannot skip ads, etc.

Related

How to get Video views count from Instgram Grapgh API in Android?

I am trying to fetch the Video Views count from Instagram API, but I can't find any API that provides the video counts, I have found this answer on Stackoverflow [How to retrieve video view count from Instagram API][1]
[1]: How to retrieve video view count from Instagram API but it doesn't work and gives me this error and response code
{
"error": {
"message": "(#200) Provide valid app ID",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "AZJFNJL_G3KzPu7VWUDlzsT"
}
}
I can't even find this Instagram API on the documentation at all, How I can get the video views count from the video URl using Instgram Grapgh API? and does instgram provide this?

Android ExoPlayer Play Private Vimeo Videos

I'm trying to play Vimeo video using ExoPlayer and here is the code:
val dataSourceFactory = DefaultDataSourceFactory(requireContext(),
getUserAgent(requireContext(), requireContext().getString(R.string.app_name)))
val videoSource = ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(videoLink))
player.prepare(videoSource)
This throw the following exception:
com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 403
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:300)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:177)
at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)
at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:961)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Also I tried to extract the Vimeo url using AndroidVimeoExtractor and it fails with the following exception:
java.io.IOException: Video has restricted playback
Here is the code:
VimeoExtractor.getInstance().fetchVideoWithIdentifier(
"videoIdentifier",
null,
object : OnVimeoExtractionListener {
override fun onSuccess(video: VimeoVideo) {
Logger.i("video: ${video.streams.size}")
}
override fun onFailure(throwable: Throwable) {
Logger.e(throwable)
}
})
And here is a sample of Vimeo video link: http://player.vimeo.com/external/videoIdentifier.sd.mp4?s=value&profile_id=value&oauth2_token_id=value
Note: I'm not the person who uploaded the video. Also, when I put the link in Google Chrome Browser it redirects to another link and plays video normally. So I need something like that to get the final link to pass it to ExoPlayer.
There is 2 ways to handle this issue
First solution
Using Vimeo networking API to get video URI and to use it
create app on vimeo developer
using your app access token and video Id you can get Video Url then pass it to Exo player
Second Solution (it's a work around and fast solution)
using web view to redirect to .mp4 url, then use the redirected url ends with.mp4 to open it with Exo player
webView = WebView(context).apply {
settings.javaScriptEnabled = false
webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val requestUrl = request?.url.toString()
val uri = requestUrl.toUri()
if (isVideoLink(requestUrl)) {
preparePlayer(uri)
webView?.release()
webView = null
return true
}
return false
}
}
loadUrl(url)
}
fun isVideoLink(url: String): Boolean {
return getMimeType(url)?.contains("video", true) ?: false
}
Are you trying to play all Vimeo Videos, or just Vimeo videos you've uploaded?
I think the issue is the mp4 file you're pulling isn't actually valid or you don't have permissions to stream it given your oauth token (if you don't own it).
You can check out the vimeo-networking library README here.
The basic requirements for native playback are:
User must be logged in.
User must be the owner of the video.
User must be PRO or higher (or the app must have the "can access owner's video files" capability).
Token must have the video_files scope.
User must be the owner of the API app making the request.
If you satisfy all of those requirements, then you can make an API request to Vimeo and they'll give you back a valid MP4 file you can pass as the videoLink.
// Obtain a video you own my making a GET request
Video video = ...;
Play play = video.getPlay();
// This will be a list of "progressive" video files (basically just MP4s of different resolutions that you can pass to ExoPlayer
ArrayList<VideoFile> progressiveFiles = play.getProgressiveVideoFiles();
String linkToMp4File = progressiveFiles.get(0).getLink();
val videoSource = ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(linkToMp4File))
If you weren't the person who uploaded the video, I think there's a way to get a valid video link, but I've never done it personally. Since all users are allowed to embed any video (if the video is public and embeddable), then you could get the embed link from the API here and then extract the MP4 file link from the embed code maybe? Just an idea.

Android - Firebase Dynamic Social Meta Tags Links on Google +

I have an application with dynamic links implemented. I'm making request to get short link with all socialMetaTagInfo defined (socialTitle, socialDescription, socialImageLink)
link is so far only dummy page with simple and whole request looks like this (I'm not filling more fields):
{
"dynamicLinkInfo": {
"dynamicLinkDomain": "dl_domain",
"link": "http://www.my_page.com",
"androidInfo": {
"androidPackageName": string
},
"socialMetaTagInfo": {
"socialTitle": string,
"socialDescription": string,
"socialImageLink": string
}
}
}
When I share result short link on Facebook I can see nice post with image, title and description. However when I share the link via Google + only link is visible without social fields. (Same for Slack for example).
Do I have to create my fallback page first? Or am I doing something wrong? I just want to know how to display the image, title and description in other social apps (pages).
Title,Desc,Images are the additional meta tags which is added to your Dynamic links.
Apps like Facebook, Twitter, Google+ will be identifying the meta data from your url and load it in the UI.
It may fail to load if the Image size is large or if Google+ app is not coded to handle it.

vimeo video play in Android native

I am developing vimeo video app in native android. But it is not supported in VideoView. May I know any samples or related query for Android. I want final output to be in .mp3/.mp4 format.
I have tried iframe in Android WebView, It works well in Android WebView but I am not able to get seek bar. And OnPause() not able to Pause the video.
Here I am able to get Pause and Play button Only
Example: player.vimeo.com/video/49462103
I want play this video in android native
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/videoView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Update link in :
Vimeo site Thread-1
Vimeo site Thread-2
I am getting above error
I made a native player for vimeo, base by WebView. Support public and private video.
Try it : https://github.com/ct7ct7ct7/Android-VimeoPlayer
<com.ct7ct7ct7.androidvimeoplayer.view.VimeoPlayerView
android:id="#+id/vimeoPlayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
VimeoPlayerView vimeoPlayer = findViewById(R.id.vimeoPlayer);
getLifecycle().addObserver(vimeoPlayer);
//public video
vimeoPlayer.initialize(59777392);
//If video is open. but limit playing at embedded.
vimeoPlayer.initialize({YourPrivateVideoId}, "SettingsEmbeddedUrl")
//If video is pirvate.
vimeoPlayer.initialize({YourPrivateVideoId},"VideoHashKey", "SettingsEmbeddedUrl")
Vimeo's embed codes should work inside an Android WebView.
Vimeo only offers .mp4 links to PRO users on those users own videos.
Another option is to use the official Deep Link library for the android application. This will let you open any vimeo video in the Android app.
You can use Exoplayer to play vimeo Videos. Exoplayer is more customizable. All you need is to extract the url link from the video config link. You may use retrofit to extract the video url.
BASE_URL = "https://player.vimeo.com/video/"
You will need to use a get method like below:
#GET("{id}/{config}")
Call<JsonObject>getVideoLink(#Path("id") String id, #Path("config") String config);
You will get the id from video link. Example: "https://vimeo.com/123456789/" Here the id is: 123456789 .
JsonObject jsonObject = response.body();
JsonObject req = jsonObject.getAsJsonObject("request");
JsonObject file = req.getAsJsonObject("files");
JsonArray arr = file.getAsJsonArray("progressive");
String url = arr.get(0).getAsJsonObject().get("url").getAsString();
// Build the media item.
MediaItem mediaItem = MediaItem.fromUri(url);
// Set the media item to be played.
player.setMediaItem(mediaItem);
// Prepare the player.
player.prepare();
// Start the playback.
player.play();
Don't forget to initiate Exoplayer first.

Can not Download video from youtube

I am using http://www.youtube.com/get_video_info?video_id=*VIDEO_ID* and from the data I get I am parsing the url_encoded_fmt_stream_map and I get the urls like
http://blah.youtube.com/videoplayback?blah
Earlier I could download the videos using this url but now I am not able to download the videos anymore. Anyone has a clue why?
Here is the code to return the video urls:
all credits to youtube-dl I only copied the part of their script which you need for extracting the urls
video_id = "yourvideoid"
for el_type in ['&el=embedded', '&el=detailpage', '&el=vevo', '']:
video_info_url = ('http://www.youtube.com/get_video_info?&video_id=%s%s& ps=default&eurl=&gl=US&hl=en'
% (video_id, el_type))
request = urllib2.Request(video_info_url)
try:
video_info_webpage = urllib2.urlopen(request).read()
video_info = parse_qs(video_info_webpage)
if 'token' in video_info:
break
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
print('ERROR: unable to download video info webpage: %s' % str(err))
video_url_list = video_info['url_encoded_fmt_stream_map'][0]
url_data_strs = video_info['url_encoded_fmt_stream_map'][0].split(',')
url_data = [parse_qs(uds) for uds in url_data_strs]
url_data = filter(lambda ud: 'itag' in ud and 'url' in ud, url_data)
url_map = dict((ud['itag'][0], ud['url'][0] + '&signature=' + ud['sig'][0]) for ud in url_data)
print(str(url_map))
No clue as to why, but it seems to be affecting all downloader extensions, so it's almost certainly on YouTube's side. I'm assuming it has something to do with intellectual property. YouTube is "intended" to be a streaming site, not a video file repository.
Shutaro at addons.mozilla.com has discovered a workaround that entails forcing YouTube to revert to delivering the older .webm format.
I am having the same problem and from what I understand from someone else who has fixed it that we need to add a signature to the video link (the mp4 or 3gp links that are returned)... I'm looking into this and will update. I hope you can do the same if you discover anything.

Categories

Resources