RSATom / WebChimera

[DEPRECATED] Web browser plugin based on Vlc + Firebreath + Qt Quick 2/Qml
GNU Lesser General Public License v2.1
82 stars 22 forks source link

question... init player #76

Closed smolleyes closed 9 years ago

smolleyes commented 9 years ago

hi

i put the player in a hidden by default in my app like this

<div id="playerContainer" style="display:none;">
        <object id="Player" type="application/x-chimera-plugin" style="height:100%;width:100%;">
        <param name="debug" value="true" />
        <param name="qmlsrc" value="player/themes/sleek/main.qml" />
        <param name="target" value="" />
        </object>
    </div>

and in my js i have a simple

player = document.getElementById('Player');

until this div is not visible or focused it seems i can t use the js api on it, how can i do ?

thanks

jaruba commented 9 years ago

Read down from here: https://github.com/RSATom/WebChimera/issues/34#issuecomment-65058889

about @gyzerok 's method (not iframe shim), it should help you solve your problem.

RSATom commented 9 years ago

yes, it's possible some browsers don't create plugin if it's hidden. It needs some trick to workaround it. I'm already met something similar, just need to remember where exactly.

RSATom commented 9 years ago

Found it, look this discussion: https://code.google.com/p/fbvlc/issues/detail?id=61

jaruba commented 9 years ago

Also, you can make the plugin window have 1px height and 1px width. It would still be loaded, just practically invisible. :)

smolleyes commented 9 years ago

hello

ok just set the main div to visibility:hidden and it works not display:none :p

<div id="playerContainer" style="visibility:hidden;">
        <object id="Player" type="application/x-chimera-plugin" style="height:100%;width:100%;">
        <param name="debug" value="true" />
        <param name="qmlsrc" value="player/themes/sleek/main.qml" />
        <param name="target" value="" />
        </object>
    </div>

now another "problem" is that i load some peerflix streams in the player and the total duration change all the time :/ (working with normal vlc) but it s another topic :p (and not all files)

smolleyes commented 9 years ago

ok so it works, but if i change tab the stream completely stop (no way to stop a media only if stop is called) ?

and attachd events are not working, for exemple

player.addEventListener('MediaPlayerStopped', function() {

do not works, it works if i declare it after player.play('.....')

RSATom commented 9 years ago

What browser do you use?

smolleyes commented 9 years ago

sorry, events are working i had some errors before my declaration of the events...

i use node-webkit 0.9.2 now so chromium: "32.0.1700.107"

RSATom commented 9 years ago

Is problem with tab change still exists?

smolleyes commented 9 years ago

ok forgot my comment on player stooping when i change tab too :p

it works, finally i just have a problem with the total length of the file (but i have the same problem in vlc) ffmpeg can get the real duration of the file, no way to force the duration in the player ? (in seconds)

smolleyes commented 9 years ago

duration with ffmpeg

C:\Users\smo>ffprobe -i http://192.168.0.36:54566/  -show_format -v quiet
[FORMAT]
filename=http://192.168.0.36:54566/
nb_streams=2
nb_programs=0
format_name=avi
format_long_name=AVI (Audio Video Interleaved)
start_time=0.000000
duration=6505.656000
size=737477910
bit_rate=906875
probe_score=100
TAG:encoder=Lavf55.18.104
[/FORMAT]

don t understand how or if i can acces the wjs object i see in the qml file from js ?

RSATom commented 9 years ago

Could you try vlc player nightly build? Maybe it's fixed in recent versions.

smolleyes commented 9 years ago

ok i try, brb

(it works on linux in vlc with peerflix)

RSATom commented 9 years ago

Sorry, don't know what wjs is

smolleyes commented 9 years ago

i try the msi from here

http://nightlies.videolan.org/build/win32/vlc-3.0.0-20150208-2058/

sorry too lol, i discover qml ... it s vlcPlayer i see it in the qml file, no way to acces it from js ?

smolleyes commented 9 years ago

humm just start a command line Oo

RSATom commented 9 years ago

https://github.com/RSATom/WebChimera/wiki/JavaScript-API All this API related to vlcPlayer instance in qml. I.e. It's no matter on which side you call functions (it has some exceptions but you could think about it as described )

RSATom commented 9 years ago

Do you mean, is it possible run ffprobe from qml?

smolleyes commented 9 years ago

don t know, i call it thru nodejs so it s not a problem but don t know if i can tell vlc or qml to use the duration i give to him

RSATom commented 9 years ago

Understand, could you please check if "position" property show correct value(it has 0 to 1 interval)?

smolleyes commented 9 years ago

player.time 103709 player.time 104549

that s why it change all the time, not way to not refresh it ? (think thru qml if i understand)

smolleyes commented 9 years ago

is see this in UIsettings.qml

Component.onCompleted: { ui = variables; done = true; } Timer { interval: 0; running: done === true && mutebut.width != ui.settings.toolbar.buttonMuteWidth ? true : false; repeat: false onTriggered: { ui = ui } } Timer { interval: 0; running: done === true && prevBut.width != buttonWidth ? true : false; repeat: false onTriggered: { buttonWidth = buttonWidth } }

??

smolleyes commented 9 years ago

where can i find the "position" you asked for ? :)

RSATom commented 9 years ago

This value I get from libvlc, so i can't change it.

jaruba commented 9 years ago

So much happened in the meanwhile..

To use wjs you need to include "player/webchimera.js" in your page, then if the plugin object has id "webchimera" for example, then you call it with wjs("#webchimera")

Where did you download WebChimera Player from? The download page or did you download a demo directly? (need to know in order to help you overwrite the total length of a video element)

smolleyes commented 9 years ago

i understand, but could we disable it and get it ourself ? (thru ffprobe for me) then sent is a time

RSATom commented 9 years ago

"position" = player.position

smolleyes commented 9 years ago

i downloaded the ratio demo jaruba and use the qml from it (to learn)

smolleyes commented 9 years ago

player.position 0.014723594300448895

it works

jaruba commented 9 years ago

ok, open the file "player\core\Functions.qml"

and look for these lines:

// Start Get Video Length in seconds
function getLength() {
    if (vlcPlayer.length > 0) {
        return vlcPlayer.length;
    } else {
        return vlcPlayer.time * (1 / vlcPlayer.position);
    }
}
// End Get Video Length in seconds

Change it to:

// Start Get Video Length in seconds
function getLength() {
    if (vlcPlayer.length > 0) {
        return vlcPlayer.length;
    } else if (settings.customLength > 0) {
        return settings.customLength;
    } else {
        return vlcPlayer.time * (1 / vlcPlayer.position);
    }
}
// End Get Video Length in seconds
RSATom commented 9 years ago

I think @jaruba will help better, I have go to sleep. Will back around 10 hours

smolleyes commented 9 years ago

ok good night RSATom, thanks :)

smolleyes commented 9 years ago

ok done jaruba, and now how can i set it from js in the app ?

jaruba commented 9 years ago

Now go to "player\core\Settings.qml" and add:

    property var customLength: 0;

where you see all the other "property var"..

Now we have a property ready to accept the custom value, all we need to do is send it from on page js to qml. So we go back to "player/core/Functions.qml" and look for:

    } else {
        if (startsWith(message,"[start-subtitle]")) subMenu.playSubtitles(message.replace("[start-subtitle]","")); // Get Subtitle URL and Play Subtitle
        if (startsWith(message,"[clear-subtitle]")) subMenu.clearSubtitles(); // Clear Loaded External Subtitle
        if (startsWith(message,"[load-m3u]")) playM3U(message.replace("[load-m3u]","")); // Load M3U Playlist URL

And we add one more line to it:

    } else {
        if (startsWith(message,"[start-subtitle]")) subMenu.playSubtitles(message.replace("[start-subtitle]","")); // Get Subtitle URL and Play Subtitle
        if (startsWith(message,"[clear-subtitle]")) subMenu.clearSubtitles(); // Clear Loaded External Subtitle
        if (startsWith(message,"[load-m3u]")) playM3U(message.replace("[load-m3u]","")); // Load M3U Playlist URL
        if (startsWith(message,"[set-total-length]")) settings.customLength = message.replace("[set-total-length]",""); // Set custom total length
jaruba commented 9 years ago

Now, if you use wjs, you can use:

wjs("#Player").plugin.emitJsMessage("[set-total-length]"+totalLength);

or without wjs:

document.getElementById('Player').emitJsMessage("[set-total-length]"+totalLength);

These examples presume you have a plugin object with id "Player" and that you have the total length in milliseconds saved in a variable by the name of "totalLength".

smolleyes commented 9 years ago

ok i understand now i call .emitJsMessage( message ) ... that s it

smolleyes commented 9 years ago

yes i have a player object i ll try now :) THANKS

and it help me understand the qml files... :palm_tree:

jaruba commented 9 years ago

Also, you should hook to the event that is triggered when the video ends and use:

wjs("#Player").plugin.emitJsMessage("[set-total-length]0");

or:

document.getElementById('Player').emitJsMessage("[set-total-length]0");

Otherwise, when the video has ended, the next video will probably have the same total length (because it overwrites all other properties except the one from vlcPlayer itself).

smolleyes commented 9 years ago

player.emitJsMessage("[set-total-length]"+6505);

it gives me 02:15 / 00:06 Oo

strange 06 seconds

jaruba commented 9 years ago

yeah, because it's in milliseconds, so 1000 milliseconds = 1 second

smolleyes commented 9 years ago

oh ok i ll try

jaruba commented 9 years ago

Also, I recommend you use the recommended method ( http://wiki.webchimera.org/Player_Embedding ) of embedding WebChimera Player, it gives a lot more options ( http://wiki.webchimera.org/Player_JavaScript_API ) and accepts all the plugin javascript api functions too.

smolleyes commented 9 years ago

ok it works :+1:

now i ll search to rehresh the progress bar, exemple i have 1:48:25 as total time but seeking in the bar stop at 43:25

jaruba commented 9 years ago

The thing is, that the progress bar has nothing to do with .time or .length, it prints the value of "vlcPlayer.progress" which has values ranging from 0.0 (0%) to 1.0 (100%) of the plugin area length.

If you want to overwrite this functionality, first you will need to make sure that you ALWAYS have the correct current time and total length available. Set a new property in "player/core/Settings.qml" (like before), then calculate the new progress by doing (do this in the "onTime()" function in "player/core/Functions.qml"):

settings.newProgress = getLength() / vlcPlayer.time;
settings = settings;

and change all "vlcPlayer.progress" to "settings.newProgress" everywhere.

This might also work without doing "settings = settings;", this is actually a hack I made to force object property notification, and I recommend it in this scenario.

smolleyes commented 9 years ago

ok thanks, i m adding the webchimera.js now

but have the QML file form local machine warning... fixing it :p

and yes ffprobe always return the good length but on real LIVE streams so don t care about progress bar in this case

jaruba commented 9 years ago

Yeah, you should be able to use "visibility:hidden" without problems, because the player container is exposed in html. (not dynamically created like the plugin object)

jaruba commented 9 years ago

To fix the local QML file warning, just remove:

// if page on local machine, add warning
var globalurlstring = " ";
var localwarning = '<div id="warning-wrapper"><div id="lwarning" class="btn">QML File cannot be loaded from your Local Machine! Upload the Demo on a Web server to see it working correctly!</div></div>';
var wjsScripts = document.getElementsByTagName("script"),
    webchimeraSrc = wjsScripts[wjsScripts.length-1].src,
    webchimeraFolder = webchimeraSrc.substring(0, webchimeraSrc.lastIndexOf("/"));
switch(window.location.protocol) {
   case 'http:': break;
   case 'https:': break
   case 'file:':
     document.body.innerHTML += localwarning;
     break;
   default: 
     document.body.innerHTML += localwarning;
}
// end if page on local machine, add warning

from "player/webchimera.js"

smolleyes commented 9 years ago

i have webchimeraFolder is not defined if i do that

i try to add case 'app:': break; but not working

jaruba commented 9 years ago

I changed my comment above about how to force the new progress. It now includes a hack that ensures that the "settings" property will be notified in qml each time it changes.

Try removing only:

switch(window.location.protocol) {
   case 'http:': break;
   case 'https:': break
   case 'file:':
     document.body.innerHTML += localwarning;
     break;
   default: 
     document.body.innerHTML += localwarning;
}

See if that helps. I have to run out for an hour or so, leave any questions you may have here and I'll answer them as soon as I get back. :)

smolleyes commented 9 years ago

ok jaruba thanks a lot !! really cool :)

i try to fix the qml loading for the moment :p