Instead of using official youtube api I want to use PierfrancescoSoffritti -android-youtube-player found on Github https://github.com/PierfrancescoSoffritti/android-youtube-player
But I am confused whether it will allow ads to run on android app or not. The documentation on Github does not specify it. Can anyone tell me whether will will support ads or not? I have tried the following code to run youtube video. The video plays correctly but it is not showing ads. But if play the same video on youtube website then ads come.
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youTubePlayerView);
youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
#Override
public void onReady(#NonNull YouTubePlayer youTubePlayer) {
String videoId = "S0Q4gqBUs7c";
youTubePlayer.loadVideo(videoId, 0);
}
});
This player is using the official web player from YouTube. Therefore ads are shown. But from what I've seen they seem to be shown less frequently than on desktop/native android player.
Related
I have a requirement of playing a YouTube video on augmented image. I'm trying to play a YouTube video on a augmented image using YouTube player API. But, the issue is video is not showing only audio is playing. Can anyone help me achieve my requirement?
Here is my xml file which I'm using for YouTube player view. I have used 3rd party library to load YouTube video.
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/youTubePlayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:showYouTubeButton="false"
app:videoId="pIAQV0u72iI"
app:showFullScreenButton="false" />
Here is me sceneform class for YouTube which i'm adding for YouTube videos.
class SwarmSceneYouTube(val image: AugmentedImage?, val arItemData: ArListData?) :
AugmentedImageNodeGroup() {
override fun onInit() {
YouTubeVideoNode().init(anchorNode, this, image, arItemData)
}
}
class YouTubeVideoNode : AugmentedImageNode(ArResources.youTubeRenderable) {
override fun initLayout() {
super.initLayout()
val youTubePlayer = ArResources.youTubeRenderable.get().view.youTubePlayer
}
override fun modifyLayout() {
super.modifyLayout()
localRotation = ArResources.youTubeRenderableRotation
}
}
I see you are using a specific library to embed the video.
This repository does not appear to have had any updates in the last last 17 months, but you will see there are some issues listed similar to your one:
https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/651
https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/646
It would be good to add you example to those discussions.
Although it is not marked as closed the most promising fix is likely this note:
Sir I debug this issue it rises when Android System WebView disabled and google chrome working is default web interface. once
Android System WebView enabled its gone automatically
Android WebView functionality can differ between devices so there can be issues with support for some features. This has been know to affect DRM in particular which in turn will often show the symptoms you are seeing of audio but no video playback. See this answer: https://stackoverflow.com/a/47688092/334402
Given the lack of recent activity it would probably be good to check the official YouTube API also.
This is a fairly basic question I think. If a site uses the YouTube API to embed videos on it, will plays to that video also register as plays on the YouTube site itself, or are those plays only counted for people that actually play the video on YouTube.com?
I searched through google and Youtube docs, but didn't see anything relevant, but I could have missed seeing it.
They would count as normal plays via YouTube website if you use official IFrame player API for embedding.
Note: A playback only counts toward a video's official view count if
it is initiated via a native play button in the player.
However, note if autoplay is enabled, views will not increase.
See here: Embedded youtube video with "autoplay=1". Does it count towards views?.
When I watch videos in the official youtube app on my Android device, I see the familiar cast icon in the toolbar, which sends the playing video to my chromecast.
I want to write my own app that uses the official youtube player API for Android. Playing with the Android samples (https://developers.google.com/youtube/android/player/sample-applications), I've noticed that the chromecast icon is missing.
What is the best way to add chromecast support to my app which uses YoutubePlayerView or YoutubePlayerFragment to play videos?
Well, if you want to use chromecast for the YouTube API, then you can start by knowing how to integrate Cast in an Android App. You will learn here the basic information that you need to know. Also, check this YouTube Android Player API to know how it is works.
I found here a demo that shows how to integrate YouTube APIs with Chromecast. It is designed for developers who are learning about the Chromecast SDK or YouTube APIs, or for those wishing to run a code lab on various Google technologies.
I know this question seems to have been asked before, but it apparently hasn't (at least on stack overflow). I get the following error using Youtube iOS helper api for certain videos when I attempt to embed them in my iOS app.
"This video contains content from VEVO. It is restricted from playback on certain sites."
The error below is fairly self explanatory... and it appears that there is nothing you can do about it. I can live with that. But there is more to it.
The reason I am puzzled by this message (and it refers to any VEVO music video on Youtube) is that the videos play on Android. Someone else has also had this problem... stated here: https://github.com/youtube/youtube-ios-player-helper/issues/52
If there is a restriction on other sites - and there may well be - it should be restricted on both iOS and Android devices. I find it highly odd that the restriction applies to only iOS.
Can someone advise?
Cheers!
add this in your playerVars #"origin" :#"http://www.youtube.com" it will work. I had the same problem.. i solved it using playvars
According to this answer,
...iOS devices use iframe so they basically embed. Android devices that
use player API can check syndicated.
From the documentation: if a video is embeddable, it can be embedded into a webpage, and if it is syndicated, it can be played outside of youtube.com.
A video that is embeddable but not syndicatable will play on YouTube.com or on other sites that embed the YouTube player, but may not play on devices such as mobile phones or TVs (source). Therefore, if a video plays on Android but not on iOS, it's possible that it's syndicateable but not embeddable, in which case it's working as intended.
I am creating an iOS app that uses the youtube iOS player helper. It works fine, but for some videos, when trying to play them, I get 'This video contains content from [YYY]. It is restricted from playback on certain sites'.
The metadata for one of the videos that doesn't work is here: http://gdata.youtube.com/feeds/api/videos/KJB49SAHIKM?v=2&prettyprint=true.
And http://gdata.youtube.com/feeds/api/videos/dRgPi1OPBeA?v=2&prettyprint=true is the metadata for a video that works.
The embed permission seems to be the same. What could the problem be? Is there something I'm missing?
I know that 'syndicate' is denied for the video that doesn't work, but I also have a video with syndicate and embed allowed that doesn't play and gives the same error, so I assume there must be something else.
Also, I have access to the channels that uploaded those two videos. Are there any settings for the individual videos that have to be set for them to be able to be embedded?
Add player vars while initializing youtube sdk:
NSDictionary *playerVars = #{
#"origin" : #"http://www.youtube.com",
};
[self.playerView loadWithVideoId:#"KOvoD1upTxM" playerVars:playerVars];
Enjoy!
I had the same issue but it seems like its due to the fact that publishers have restricted the video to be played outside youtube.com. If you own the channel and videos then probably you have a setting that restricts playback of videos outside youtube. For other videos that I dont have access to I put an option to watch it on youtube that would fire up native youtube app with the video loaded.