You know how at the end of playing a movie the YouTube player shows you suggestions and a search box? Well, I'd like to embed a YouTube player in that state. No video- just a search box and suggestions. Is this possible?
Ok, you can set whatever video you want, and then use Splicd to trim the video to about one second or less, then simply set autoplay to yes, and you have a window with suggestions. This may be to hacky as my previous suggestion was though.
You could cue the video to autostart at the end, meaning it'll play for about a second before showing the suggestions. To avoid showing that 1 second of video, you could mute and hide the video until its finished. Something like this:
window.onload=function(){
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer", bgcolor: "#000" };
swfobject.embedSWF("http://www.youtube.com/e/KmDYXaaT9sA?enablejsapi=1&version=3&playerapiid=ytplayer&showinfo=0&start=99999&autoplay=1",
"ytapiplayer", "425", "356", "8", null, null, params, atts);
}
var first = true;
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
ytplayer.mute();
ytplayer.style.visibility = "hidden";
}
function onytplayerStateChange(newState) {
ytplayer = document.getElementById("myytplayer");
if (newState==0 && first) {
first=false;
ytplayer.style.visibility = "visible";
ytplayer.unMute();
}
}
example: http://fiddle.jshell.net/niklasvh/thpZM/show/
Related
following the instructions from:
https://codingwithjoe.com/playing-audio-from-the-web-and-http/ (using his example and AudioProvider class)
I have been using:
audioplayer: ^0.8.1
audioplayer_web: ^0.7.1
to play audio from https link.
The problem it has some weird inconsistent effect.
- after playing few audio, it keeps on playing the same audio eventhough new url is loaded
- after playing few audio, the sound is weird like some part is cut with other audio.
What is a good audio player that accepts url link for flutter that can produce a consistent result ?
the provided audioplayer from your example works great and has good features. From what you are describing for me it seems like you're not closing the session when you play a sound. It seems like you are stacking the sounds which causes weird sounds.
You have to close the instance then. even though the article is outdated (march 2018) the audioplayer has developed further. check their offical guide here:
https://pub.dev/packages/audioplayer
This is version audioplayer 0.8.1 not 3.0 or something..
Example from docs:
Instantiate an AudioPlayer instance
//...
AudioPlayer audioPlugin = AudioPlayer();
//...
Player controls:
audioPlayer.play(url);
audioPlayer.pause();
audioPlayer.stop();
status and current position:
//...
_positionSubscription = audioPlayer.onAudioPositionChanged.listen(
(p) => setState(() => position = p)
);
_audioPlayerStateSubscription = audioPlayer.onPlayerStateChanged.listen((s) {
if (s == AudioPlayerState.PLAYING) {
setState(() => duration = audioPlayer.duration);
} else if (s == AudioPlayerState.STOPPED) {
onComplete();
setState(() {
position = duration;
});
}
}, onError: (msg) {
setState(() {
playerState = PlayerState.stopped;
duration = new Duration(seconds: 0);
position = new Duration(seconds: 0);
});
});
Like I said most of the audio plugins are running in singleton mode with instances. To provide getting weird effects you have to load the next song in the same instance, don't open another new instance, and you wont get any weird effects.
If you want to switch to a different audio player another great one which I used in an app project is the following:
https://pub.dev/packages/audio_manager#-readme-tab-
Hope it helps.
Is there any way to play one youtube video after another, or better yet, play a sequence of videos one after another with no breaks inbetween? I'm unsure how to do this using the youtube API, but I know it can be done somehow.
The easiest way is using Youtube API method to specify a playlist (check the docs). The harder way is to play the videos yourself, listening for the Video End event, then playing the next one.
About no breaks, that depends on a lot of things:
The speed of the internet connection
wether the videos have ads or not
If the videos have no ads, and you are not satisfied with the breaks you are getting, you might try to cue the next video say 5 seconds before the former video ends, then when you get the Video Finish event, just send a play to the next video. To do this, you have to sequence the videos yourself.
This is simple. I am assuming you have an array of video IDs you want to play. In your onStageChange function, listen for video ended state and once that happens, pick next video from array and start playing it. To play the next video, you need to call loadVideoById function followed by playVideo() call. Hope this helped.
And as #rupps said, whether your videos will run without any breaks one after another depends on factors like internet speed. You cannot buffer all videos of a playlist beforehand.
Visit this post to view the sample - Play a 2nd youtube video after first one has finished playing
I am having an array of video IDs that want to play. In your onStageChange function, on the video ended state, pick next video from array and start playing it. At the end of all array videos it will start again from initial.
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var videoId = ['gCFpK_z0Y1o', '2XXzYCfBiAg', 'H-N2SynCSEs', '6PDBRoRFYvo'];
var player; currentVideoId = 0;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
playerVars: {
autoplay: 1,
// loop: 1,
// rel: 0,
// showinfo: 0,
// autohide: 0,
// modestbranding: 1,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.loadVideoById(videoId[currentVideoId]);
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
currentVideoId++;
if (currentVideoId < videoId.length) {
player.loadVideoById(videoId[currentVideoId]);
} else {
currentVideoId = 0;
event.target.loadVideoById(videoId[currentVideoId]);
}
}
}
I have the following code, where I hoped to be able to console.log out the list of videos in the playlist:
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.cuePlaylist({
list:"PLf71xE2jRgTXB_LeUJkXxFwCc4r1z5if3"
});
console.log(ytplayer.getPlaylist());
}
But the getPlayList() method just returns an empty array.
When playing around with it if I call getPlaylist() from outside of this function it does return the correct array. Why is this method returning an empty array here? And how can I get the playlist array?
Many thanks.
Just stumbled across this problem myself. The issue seems to be a quirk with the player, and how YouTube (google) have defined "ready"
It seems that the onReady function of the player fires when the "chrome" for the player has finished rendering (i.e. it's tied the HTML document). The actual player data (video or playlist) is loaded asynchronously, so is ready at some arbitrary point after.
I put a simple work-around in place that looks at the state-change event of the player
var firstLoad = true;
function onPlayerStateChange(e) {
if (firstLoad && e.data == YT.PlayerState.CUED) {
//First Cued event - playlist is now available
firstLoad = false
myPlaylistFunction(player.getPlaylist());
}
}
I have the following code to play the sound. However nothing is happening when I press the button. The sound file is located in Resource folder. Need help in this.
var playButton = Ti.UI.createButton({
title:'play',
borderRadius : 'black',
top:40,
right:65,
width:50,
height:50
})
playButton.addEventListener('click',function(e){
var sound = Titanium.Media.createSound({
sound : "1-0.wav"
});
sound.play();
})
According to the docs: http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Media.Sound
It shows the sound being assigned to a url param of the createSound call.
var player = Ti.Media.createSound({url:"sound.wav"});
player.play();
I'm not seeing a 'sound' param in the most recent docs, but perhaps you are using an older version of the SDK.
I think there is no sound property available for the media.
You need to use the url property instead.
playButton.addEventListener('click',function(e){
var sound = Ti.Media.createSound({
url:"1.0.wav"
});
sound.play();
})
Reference Titanium Media
I have a web page that plays an embedded sound. If I "close" the browser on the iPad while the sound is playing, the sound does not stop. How can I make the sound stop playing when the browser is not visible?
Thought I'd let you know, since I just managed to find a solution.
Code like this, should work:
var lastSeen;
var loop = function (){
lastSeen = Date.now();
setTimeout(loop, 50);
};
loop();
var music = document.getElementById('music');
music.addEventListener('timeupdate', function (){
if(Date.now() - exports.lastSeen > 100){
this.pause();
}
}, false);