I’m trying to get something like an index page of a youtube video so that there are links to specific times of the video.
I tried it to do like explained in Links to Specific Times in YouTube iframe embed, but somehow it doesnt seem to work.
This is my code:
<script>
var tag = document.createElement('script');
tag.src = "//www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('video', { events: {'onReady': onPlayerReady}});
}
function playerSeekTo(seconds) {
player.seekTo(seconds);
}
</script>
HTML:
<iframe src="https://www.youtube.com/embed/FKWwdQu6_ok?enablejsapi=1" frameborder="0" allowfullscreen id="video">
</iframe>
Link to 1 minutes 10 seconds
Link to 1 minutes 30seconds
Link to 1 minutes 50 seconds
I encountered three problems:
1st
tag.src = "//www.youtube.com/player_api";
led to an error. Should be
tag.src = "http://www.youtube.com/player_api";
2nd
player = new YT.Player('video', { events: {'onReady': onPlayerReady}});
Obviously, onPlayerReady is not defined. When you remove this part, it'll work fine. What do you want to achieve with this?
player = new YT.Player('video');
(3rd)
To me, the video you embed is not available. When I embed another video (e.g. Im69kzhpR3I), everything behaves as it should.
Related
I am using C# .NET with the YouTubeAPI-Nuget Package but that shouldn't be that important because I can apply concepts from every language.
I need to get all Playlists of a channel (specifically the logged-in channel, using the "mine"-parameter) and every video of each playlist quite often, I already tried to do it as rarely as possible but it still has to happen quite often.
The problem is that it takes a long time because I first have to get all playlists (1 API call for every 50 Playlists) and then per playlist get every video (1 API-call per 50 videos per playlist).
So this can multiply quite quickly. For 39 Playlists all with < 50 videos this takes a few seconds every time.
So my question is: is there any better/more efficient way?
My Optimizations:
just try to do this as rarely as possible
Don't include "Liked Videos", "Uploads" and similar unneeded Playlists in the second step (I would exclude them but they aren't included in the first place for some reason)
Code Example of how I currently do it:
private async Task InitPlaylists()
{
var playlists = new Dictionary<string, string>();
var page = "";
while (true)
{
var request = _youTubeService.Playlists.List("snippet");
request.Mine = true;
request.PageToken = page;
request.MaxResults = 50;
var result = await request.ExecuteAsync();
foreach (var playlist in result.Items) playlists.Add(playlist.Id, playlist.Snippet.Title);
if (result.NextPageToken == null) break;
page = result.NextPageToken;
}
foreach (var (id, title) in playlists)
{
var videos = new List<PlaylistItem>();
page = "";
while (true)
{
var listRequest = _youTubeService.PlaylistItems.List("id,snippet");
listRequest.PageToken = page;
listRequest.MaxResults = 50;
listRequest.PlaylistId = id;
var listResult = await listRequest.ExecuteAsync();
videos.AddRange(listResult.Items);
if (listResult.NextPageToken == null) break;
page = listResult.NextPageToken;
}
Playlists.Add(new Playlist(id, title, videos.ToDistinctDictionary()));
}
}
EDIT: Maybe it helps if I say why I need this, maybe someone has an idea how to cut some calls that way:
I want to be able to add and remove videos from playlists, like on the youtube studio edit page.
So I need A. every playlist of the channel and B. every video of every playlist because I need to know if the video is already in the playlist
If you only manipulate your YouTube channel through your script then you can keep track of current playlists' videos state. If that's not the case only multithreading can make your check faster by using a thread for each playlist. Here is a quota-free and possibly faster way of getting every video id of a playlist using youtube-dl -j --flat-playlist.
I want to build an Apple TV app that plays a list of short videos and plays music over them.
To achieve this I need to do two following things:
1) Mute the videos or remove the audio tracks from them
I have no Idea if/how this is possible. I looked around the TVJS documentation for Player and MediaItem but found nothing.
2) Play two media items at the same time.
From this I already know that this is at least not possible with two players. I also tried to use the background audio of my TVML Template but this didn't work either.
Does anyone know of a way how something like this would be possible?
Edit (some more information):
For testing stuff I used the code from this article
At the suggesion of Daniel Storm I tried to change the load function in Presenter.js to both
load: function(event) {
var self = this,
ele = event.target,
videoURL = ele.getAttribute("videoURL")
if(videoURL) {
var player = new Player();
var playlist = new Playlist();
var mediaItem = new MediaItem("video", videoURL);
player.playlist = playlist;
player.playlist.push(mediaItem);
mediaItem.volume = 0.0;
player.present();
}
},
and
load: function(event) {
var self = this,
ele = event.target,
videoURL = ele.getAttribute("videoURL")
if(videoURL) {
var player = new Player();
var playlist = new Playlist();
var mediaItem = new MediaItem("video", videoURL);
player.playlist = playlist;
player.playlist.push(mediaItem);
player.volume = 0.0;
player.present();
}
},
but neither worked.
I have several PDF files on my computer that contain links to other pages. Those links, however, direct you to the local filesystem instead of the internet. I.e. clicking the link opens the browser and takes you to file:///page instead of http://domain/page.
Getting these files modified to include the full URL is not an option.
I tried using available Firefox extensions to redirect the URL, but none worked, so I tried creating my own extension to do the same. What I've found so far is that the URL isn't accessible until the tab's "ready" event fires, but a page referring to a local file without the full path is always "uninitialized."
Here's my extension script, almost straight from https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs:
var tabs = require("sdk/tabs");
tabs.on('open', function(tab){
tab.on('ready', function(tab){
if (tab.url.indexOf("file:///page") != -1) {
tab.url = tab.url.replace("file://", "https://domain");
}
});
});
Any ideas how to go about redirecting a page from a local file to another location?
The following snippet works fine with me.
In main.js:
var tabs = require("sdk/tabs");
tabs.on('ready', function(tab){
var new_url = tab.url;
if (tab.url.indexOf("file:///") != -1) {
new_url = new_url.replace("file:///", "https://domain/");
tab.url = new_url;
}
});
Although, my Firefox didn't fire the ready event on my tab when the url is something like what you want. For example, when the url is file:///page/lala.pdf, firefox ignores the url and does not try to reach it.
I believe Firefox wants a "real" path to load the page such as file:///C:page/lala.pdf.
I hope this will help you.
The easiest way I've found to do this is actually from another StackOverflow answer... Get Content of Location Bar. Use the function in that answer to retrieve the URL and then redirect based on that. So I end up with the following:
var tabs = require("sdk/tabs");
tabs.on('open', function(tab){
tab.on('activate', function(tab){
var { getMostRecentWindow } = require("sdk/window/utils");
var urlBar = getMostRecentWindow().document.getElementById('urlbar');
if (urlBar.value.indexOf("file:///page/") != -1) {
tab.url = urlBar.value.replace("file://", "https://domain");
}
});
});
i've been struggling with this subject for ages, since there does not seem to be a concrete answer.
I'm creating a playlist of youtube videos and i would like to get notification when you press fastforward and so.The problem is my youtube video is being played by a htmlsting, which does not use a MPMoviePlayerController property. Therefor i cant use NSNotifications, which i need.
a lot of people telling me to use LBMoviePlayer or other sample codes there are extracting the youtube video. The problem is that, this is illegal and probably wont make the app through the review.
My question is then. Can it really be true that there are no way to play a youtube video and get notifications when any of the buttons pressed, without using an extractor?
my code atm:
NSString *youTubeVideoHTML = #"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%#', events: { } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
embedHtml = [NSString stringWithFormat: youTubeVideoHTML,
webView.frame.size.width,
webView.frame.size.height,
[[array valueForKey:#"link"] objectAtIndex:0 ]];
[webView loadHTMLString: embedHtml baseURL: [NSURL URLWithString: #"http://youtube.com"]];
Hello I've been expirimenting with the Google Picker API (http://code.google.com/apis/picker/). I've got a working demo (code below) that searches for YouTube movies.
This current version returns all videos. I'm trying to filter the results so it'll only list search results from youtube.com. The picker API supports this. But I don't understand the API documentation.
The documentation (http://code.google.com/apis/picker/docs/reference.html) mentions 'VideoSearchView.YOUTUBE' and describes it as "A string constant suitable for the VideoSearchView.setSite() method".
I don't understand how to implement this filter in my code below. Any help is appreciated.
<!--
Needs work; it should only display YouTube videos.
http://code.google.com/apis/picker/docs/reference.html
Change the key parameter for a domain+path specific API key. Get one here: http://code.google.com/apis/loader/signup.html.
-->
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAANAaPTI0Sup-knGFaDbCNHBSXhCTdTCKo5q_OHnpA1qEpBIP8mRTtPnObFFbe_J21oviL78C86yxHUA"></script>
<script type="text/javascript">
google.load('picker', '1', {'language':'nl'});
function googlePicker()
{
/*
Displays the users own YouTube movies:
picker = picker.addView(google.picker.ViewId.YOUTUBE);
Displays all videos:
picker = picker.addView(google.picker.ViewId.VIDEO_SEARCH);
Displays all videos from youtube.com:
???
Example query that returns non-YouTube results: "Mobile Healing Rooms: Following Jesus on Vimeo"
*/
var picker = new google.picker.PickerBuilder();
picker = picker.addView(google.picker.ViewId.VIDEO_SEARCH);
picker = picker.enableFeature(google.picker.Feature.NAV_HIDDEN);
picker = picker.setTitle('Selecteer een YouTube video');
picker = picker.setCallback(googlePickerCallback);
picker = picker.build();
picker.setVisible(true);
}
function googlePickerCallback(data) {
var youTubeUrl = (data.action == google.picker.Action.PICKED) ? data.docs[0].url : '';
if (youTubeUrl != '')
{
$('#block_youtube_url').val(youTubeUrl);
}
}
</script>
Try the equivalent of the following:
// Create and render a Picker object for searching YouTube videos.
function createPicker() {
var picker = new google.picker.PickerBuilder().
addView(new google.picker.VideoSearchView().
setSite(google.picker.VideoSearchView.YOUTUBE)).
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
If you add views by ViewId, you don't get a chance to call view-specific methods. This is why some View-derived classes are exposed.