vlc onlistnener needed to know the end of the video - vlc

Im using VLC to play video but I need to know when the video ends. so basically I need a onlistener. Can someone give me a simple code for onlistener for VLC. Here is the code I'm using to play VLC :
int vlcRequestCode = 42; Uri uri = Uri.parse("/storage/emulated/0/Download/hero.mp4");
vlcIntent.setComponent(new ComponentName("org.videolan.vlc", "org.videolan.vlc.gui.video.VideoPlayerActivity"));
vlcIntent.setDataAndTypeAndNormalize(uri, "video/*");
vlcIntent.putExtra("title", " Concert Collection");
vlcIntent.putExtra("from_start", true);
vlcIntent.putExtra("position", 90000l);
vlcIntent.putExtra("position", 90000l);
startActivityForResult(vlcIntent, vlcRequestCode);

Related

YouTube API: differentiating between Premiered and Livestream

I am using YouTube data API and trying to differentiate prior livestreams vs premiered content. The liveStreamingDetails in the video list is populated for both livestreams and premiered content. Is there a way I can differentiate between the two?
Below is my python code for getting live stream start time. If its not populated, then I know that video is not live stream. But the problem is that this value is getting populated for premiered content as well.
vid_request = youtube.videos().list(part = 'contentDetails, statistics, snippet, liveStreamingDetails, status',id = ','.join(vid_ids))
vid_response = vid_request.execute()
for videoitem in vid_response['items']:
try:
livestreamStartTime = videoitem['liveStreamingDetails']['actualStartTime']
except:
livestreamStartTime = ''
Any pointers on what could work would really help?

How to extract Dart/Flutter video metadata

I am developing a flutter demo app. I want to use metadata about a video in my phone storage. I am able to extract the path of that video, but don't know how to extract its metadata in dart/flutter.
I need the following metadata:
Duration of video
Name of video
Size of video
When video was taken
You can use the VideoPlayerController.file constructor from the official video player plugin (which is maintained by the official google team so you don't have to worry about its future and stability) to access the file and get the following meta after you install the package:
first this is your VideoPlayerController:
VideoPlayerController controller = new VideoPlayerController.file('');//Your file here
Duration:
controller.value.duration ;
Video Name, this should already be possessed with you as you can reach the file path and pass it to the player constructor.
3.Video Size:
controller.value.size ;
4.As for when the video was taken I can't help you with this. You have to find another way to figure it out.
One of the ways to get the creation time of the video in FLutter is to use flutter_ffmpeg plugin.
Add it to the pubspec.yaml:
dependencies:
flutter_ffmpeg: ^0.3.0
Get the file path of your video, for example with file_picker:
File pickedFile = await FilePicker.getFile();
Get meta data of the video by its path using ffmpeg:
final FlutterFFprobe flutterFFprobe = FlutterFFprobe();
MediaInformation mediaInformation = await flutterFFprobe.getMediaInformation(pickedFile.path);
Map<dynamic, dynamic> mp = mediaInformation.getMediaProperties();
String creationTime = mp["tags"]["creation_time"];
print("creationTime: $creationTime");
And in the console you'll get smth like this:
I/flutter (13274): creationTime: 2020-09-24T17:59:24.000000Z
Along with creation time, there are other useful details:
Note: adding this plugin to your app increases the weight of your final apk!
your code is correct Mazin Ibrahim you just need to initialize it. the future value will return all the details.
Future getVideo() async {
await MultiMediaPicker.pickVideo(source: ImageSource.gallery).then((video){
File _video = video;
VideoPlayerController fileVideocontroller = new VideoPlayerController.file(_video)
..initialize().then((_) {
debugPrint("========"+fileVideocontroller.value.duration.toString());
});
});
}

Online audio stream using ruby on rails

I'm trying to write small website that can stream audio online(radio station) and got few questions:
1. Do i have to index all my music files into database, or i can randomily pick file from file system and play it.
2. When should i use ajax to load new song(right after last finished, or few seconds before to get responce from server with link to file?)
3. Is it worth to use ajax, or better make list, that will play its full time and then start over?
I think you are asking the wrong Questions.
You need to think about how you will play the Audio in the browser (what player will you be using?).
You don't need Ruby on Rails to deliver the Files to the client. They can be requested directly from the Web server (Apache or Nginx)
Rails is only required for rendering the Website alongside the Player that will then play the Audio. Depending on what player you are using you can either control it through javascript to request the next song from the server or simply write a static playlist to the client that then gets played.
Regarding the streaming I aggree with #Tigraine
Now,
Single song play:
1 if you want to play an individual song then in your ajax call to action return a key value pair in json response which contains the audio URL of requested song.
For Playlist:
2. You should return an array which contains the audio URL in the same arrangement as they were added into playlist.
Then in your java script declare variable
var current_song
var total_song
In js audio player we commonly have methods which detects when the song completes and then on song complete you can increment the song counter as
current_song+=0
when the counter reaches to end reset it to one:
Sample code is:
Here I am using Jplayer you can use any other player which one of the best and fully customizable player.
var current_song = 0;
var total_songs;
var song_id_array;
$.ajax({
url:"<%=url_for :controller => 'cont_x',:action => 'song_in_playlist'%>",
data:'playlist_id=' + encodeURIComponent(playlist_id),
cache:false,
success:function (data) {
song_id_array = data.array; //data.array variable contain's the audio URL's array of songs inside selected playlist which is returned by the action //
total_songs = song_id_array.length;
}
})
current_song = 0;
play_right_song(current_song);
}
function play_right_song(current_song) {
$("#jquery_jplayer_1").jPlayer("destroy");
var audio_url_inside = song_id_array[current_song];
$('#jquery_jplayer_1').jPlayer({
ready:function (event) {
$(this).jPlayer("setMedia", {
mp3:audio_url_inside
}).jPlayer("play");
},
ended:function () { // The $.jPlayer.event.ended event
current_song += 1;
if (current_song >= total_songs) {
current_song = 0;
}
play_right_song(current_song);
},
swfPath:"<%= asset_path('Jplayer.swf')%>",
supplied:"mp3"
});
}
and if you want to handle next and previous song in playlist just ask for the code. I will update the answer.

Using get_video on YouTube to download a video

I am trying to get the video URL of any YouTube video like this:
Open
http://youtube.com/get_video_info?video_id=VIDEOID
then take the account_playback_token token value and open this URL:
http://www.youtube.com/get_video?video_id=VIDEOID&t=TOKEN&fmt=18&asv=2
This should open a page with just the video or start a download of the video. But nothing happens, Safari's activity window says 'Not found', so there is something wrong with the URL. I want to integrate this into a iPad app, and the javascript method to get the video URL I use in the iPhone version of the app isn't working, so I need another solution.
YouTube changes all the time, and I think the URL is just outdated. Please help :)
Edit: It seems like the get_video method doesn't work anymore. I'd really appreciate if anybody could tell me another way to find the video URL.
Thank you, I really need help.
Sorry, that is not possible anymore. They limit the token to the IP that got it.
Here's a workaround by using the get_headers() function, which gives you an array with the link to the video. I don't know anything about ios, so hopefully you can rewrite this PHP code yourself.
<?php
if(empty($_GET['id'])) {
echo "No id found!";
}
else {
function url_exists($url) {
if(file_get_contents($url, FALSE, NULL, 0, 0) === false) return false;
return true;
}
$id = $_GET['id'];
$page = #file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$id);
preg_match('/token=(.*?)&thumbnail_url=/', $page, $token);
$token = urldecode($token[1]);
$get = $title->video_details;
$url_array = array ("http://youtube.com/get_video?video_id=".$id."&t=".$token,
"http://youtube.com/get_video?video_id=".$id."&t=".$token."&fmt=18");
if(url_exists($url_array[1]) === true) {
$file = get_headers($url_array[1]);
}
elseif(url_exists($url_array[0]) === true) {
$file = get_headers($url_array[0]);
}
$url = trim($file[19],"Location: ");
echo 'Download video';
}
?>
I use this and it rocks: http://rg3.github.com/youtube-dl/
Just copy a YouTube URL from your browser and execute this command with the YouTube URL as the only argument. It will figure out how to find the best quality video and download it for you.
Great! I needed a way to grab a whole playlist of videos.
In Linux, this is what I used:
y=http://www.youtube.com;
f="http://gdata.youtube.com/feeds/api/playlists/PLeHqhPDNAZY_3377_DpzRSMh9MA9UbIEN?start-index=26";
for i in $(curl -s $f |grep -o "url='$y/watch?v=[^']'");do d=$(echo
$i|sed "s|url\='$y/watch?v=(.)&.*'|\1|"); youtube-dl
--restrict-filenames "$y/watch?v=$d"; done
You have to find the playlist ID from a common Youtube URL like:
https://www.youtube.com/playlist?list=PLeHqhPDNAZY_3377_DpzRSMh9MA9UbIEN
Also, this technique uses gdata API, limiting 25 records per page.
Hence the ?start-index=26 parameter (to get page 2 in my example)
This could use some cleaning, and extra logic to iterate thru all sets of 25, too.
Credits:
https://stackoverflow.com/a/8761493/1069375
http://www.commandlinefu.com/commands/view/3154/download-youtube-playlist (which itself didn't quite work)

Repeating single movie using Python bindings for VLC: what is a psz_name

I'm trying to write an little application that dynamically plays a single movie file repeatedly. I wrote it in Python, using these VLC-Python bindings
I would say that this wouldn't be so hard and even though the very sparse documentation I can get a movie fullscreen without anything else on the screen and even change the file I want to play. What I cannot is simply let a single movie repeat.
I use the following code:
self.media = []
A --repeat-tag here:
self.vlc_inst = vlc.Instance('--mouse-hide-timeout=0', '--fullscreen', '--repeat')
And a '--repeat' tag here:
self.media = self.vlc_inst.media_new(NEW_VIDEO_NAME + str(currentVideoN) + VIDEO_EXTENSION, '--repeat')
self.player = self.vlc_inst.media_player_new()
self.player.set_fullscreen(True)
self.player.set_media(self.media[currentVideoN])
self.player.play()
These repeat tags don't seem to do anything. The Instance class does have a function vlm_set_loop(self, psz_name, b_loop) but I have no idea what mrl should be. In the original code I figured out it should be a char-array (String), but I have no clue what kind of String this should be.
Anyone who does have a clue?
well, this question is pretty old, but anyways... i think instead of using '--repeat' (which only works with a medialist rather than a single mediafile afaik) in your vlc.Instance you could use somthing like '--input-repeat=999999' it's not really a loop, but as close as it gets (again: afaik ;-) )
I was able to make the media replay by setting the media to it's current media and calling play. Is the code trash? Yes, it is: the back function may not be called inside the onEnd function, else i won't full fill by some reason. Does it work? Yes
import vlc
doTrashCode = False
player = vlc.MediaPlayer("C:/Users/benj5/Videos/2019-04-29 22-14-55_Trim.mp4")
def start():
player.set_fullscreen(True)
em = player.event_manager()
em.event_attach(vlc.EventType.MediaPlayerEndReached, onEnd)
player.play()
def onEnd(event):
global doTrashCode
if event.type == vlc.EventType.MediaPlayerEndReached:
doTrashCode = True
def back():
player.set_media(player.get_media())
player.play()
start()
while True:
if doTrashCode:
back()
doTrashCode = False
you can use subprocess
p = subprocess.Popen('cvlc', 'fullscreen', 'home/pi/demo.mp4', '--loop')
I used VLC instead of CVLC earlier but it wasn't working fine for me, it was reloading and resizing the VLC player when the loop end

Resources