Unable to fetch the video title in ExoPlayer - android

Currently, I was trying to play a video from url in ExoPlayer version 2.18.1. The video play works fine but the problem arises when I try to fetch the title of the video. I searched everywhere but nowhere it shows any solution for the case that title is not being fetched.
I tried to use the onMediaMetadataChanged but that does not work. I even tried using exoPlayer#mediaMetadata but that does not work either. So, i tried placing exoPlayer#mediaMetadata in onPlayerStateChanged but that did not work either. I tried with different properties like
albumTitle
title
displayTitle
but none of them give me the result. Only I get null. What can i do to get the title? This is my code I am using to play the video in case that makes any difference:
exoPlayer = ExoPlayer.Builder(this).build()
binding.player.player = exoPlayer
val url = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
val mediaItem = MediaItem.fromUri(url)
exoPlayer.addMediaItem(mediaItem)
exoPlayer.playWhenReady = true
exoPlayer.addListener(this)
exoPlayer.prepare()
PS: I am using this for my video sample.

Related

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.

How to show Vimeo Videos in Android Webview?

Let's say, this is the link I'm using to show in android webview using KOTLIN. But, Only a blank page is coming.
https://vimeo.com/user92933894/review/307846259/0b380ce589
Now, here is my code:
var url = intent.getStringExtra("link")
println(url)
val videoPreferences = VideoPreferences(this)
val pointPreferences = PointPrefernce(this)
var videoIds = videoPreferences.getVideoId()
paidvideo.settings.javaScriptEnabled=true
paidvideo.settings.setSupportZoom(true)
paidvideo.webViewClient = object : WebViewClient(){
}
paidvideo.loadUrl(url)
Here the url is getting the link as extras of an intent. And the link is coming perfectly. And youtube link is working perfectly, but not the vimeo's one. BTW, I don't need autoplay option.
At last I found the answer. Actually, here "Uncaught TypeError: Cannot call method 'getItem' of null" error happened. and to solve this error, I needed to add this following line.
paidvideo.settings.domStorageEnabled = true
making domStorageEnabled true solves the problem.

How To play a video stream from exoplayer?

Hello i have problem i want to play video stream from url link but i have some issue after i use complete url link or without blank space exoplayer player library can detected but after i use file url link blank space cannot detected
example
http://www.something.com/folder/hmmm.mp4 //worked success
after i use this
http://www.something.com/folder/hmmm iknow this blank space.mp4// cannot worked
can someone helpme please thanks
I am gonna answer using the code I used to play video at a URL in exoplayer--
String videoURL="https://d17h27t6h515a5.cloudfront.net/topher/2017/April/58ffdcc8_5-mix-wet-and-cry-batter-together-brownies/5-mix-wet-and-cry-batter-together-brownies.mp4" ;
MediaSource mediaSource = ExtractorMediaSource.Factory(new DefaultHttpDataSourceFactory("exoplayer-codelab"))
.createMediaSource(Uri.parse(videoURL));
So you'll have to give the entire address of video along with video type extension to run successfully.

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