Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Please add currentPlaybackTime to Titanium.Media.VideoPlayer

Would be really useful to have this. Its been in the iOS SDK since 3.2: http://stackoverflow.com/questions/3163388

— asked October 2nd 2010 by James Low
  • iphone
  • videoplayer
0 Comments

10 Answers

  • OOOh currentPlaybacktime seems to be already added in 1.6.2 !
    BUT, it is not possible to set the value, I add function in TiMediaPlayerProxy.m this way:

    -(void)setcurrentPlaybackTime:(id)value
    {
        [self player].currentPlaybackTime=[TiUtils doubleValue:value];
    
    }
    

    And in your app.js, just write this to seek to the time you want:

    VideoPlayer.setcurrentPlaybacktime(15);        //For 15 seconds
    
    — answered July 7th 2011 by Yoann WYFFELS
    permalink
    11 Comments
    • In TiMediaPlayerProxy.m ? You mean TiMediaVideoPlayerProxy.m ?
      I tried to add it to TiMediaVideoPlayerProxy.m in the build folder, but nothing happens when the function is called

      — commented July 7th 2011 by Maxime Layat
    • Yes, you're right, I mean TiMediaVideoPlayerProxy.m :)

      You need to rebuild your application (because .m and .h are already linked at the first run).

      To do it, simply delete the "build" folder in "Your Project Directory\build\build" (the last "build" directory is the one to delete), and launch your application in titanium dev or studio.

      you may also apply the TiMediaVideoPlayerProxy.m modifications directly in the titanium sdk sources : futur projects will directly have the improved version ;)
      /Library/Application Support/Titanium/mobilesdk/osx/1.6.2/iphone/Classes
      (and change 1.6.2 with the sdk version you have)

      — commented July 7th 2011 by Yoann WYFFELS
    • Thank you for this tip. Could you explain how to make this change in the source. Do I update /Library/Application Support/Titanium/mobilesdk/osx/17.1/iphone/Classes/TiMediaVideoPlayerProxy.m with your set method and then re-compile my app? Or do I need to update my local copy of the source and re-run scons? When I try to build titanium from the source on my MacBook it looks like only the android is built. I'm new to this world - sorry if these questions are lame. I really need to be able to seek without first stopping the video. Thank you!

      — commented July 21st 2011 by Chris Caruso
    • It is already explain how to make change to SDK sources in my old thread. Two ways to do it:

      if you want to make change in the main SDK (for all your futur projects), simply modify the TiMediaVideoPlayerProxy.m in the /Library/Application Support/Titanium/mobilesdk/osx/1.7.1/iphone/Classes

      Or if you want to make change only for your project, modify the TiMediaVideoPlayerProxy.m in the build/iphone/Classes in your project directory

      For both solutions, you need to do a full rebuild by deleting "Your Project Directory\build\build" directory

      — commented July 22nd 2011 by Yoann WYFFELS
    • Thank you for your reply. I finally found my problem. The post (which was very, very helpful) defines the setter as 'setcurrentPlaybackTime' and the example uses 'setcurrentPlaybacktime' - small 't' ! I copied and pasted directly from the post - I must be getting old. Thank you again.

      — commented July 22nd 2011 by Chris Caruso
    • Ohhhh this is glorious!!! I've been trying to accomplish this for so long. And yes, please get this in the API so we don't have to hack! Either way, I'm a happy camper right now. :)

      — commented September 7th 2011 by Nick Robillard
    • I'll take a look at getting a pull request in for this.

      — commented October 11th 2011 by Kevin Whinnery
    • Hi, it looks like this is for iOS, how can I enable something like this for Android also?

      — commented December 22nd 2011 by Ki Hwan Song
    • Well this has been working nicely for me pre 1.8.0.1. However, now that I've upgraded to 1.8.0.1, setcurrentPlaybacktime always sets the playback to 0. :( Anyone know what changed? I'm seeing that other playback values and durations are now in milliseconds but I don't think that should affect this.

      — commented January 4th 2012 by Nick Robillard
    • hi,

      I m getting error win.setcurrentPlaybackTime[undefined] is not function

      — commented March 14th 2012 by Amol Jadhav
    • hi again,

      now I m not getting error but still its not working(doing nothing)..

      — commented March 15th 2012 by Amol Jadhav
  • I've managed to use this by adding the following to TiMediaVideoPlayerProxy.m but it would be great if it was in the main code.

    -(NSNumber*)currentPlaybackTime
    {
        if (movie != nil) {
            return NUMDOUBLE([[self player] currentPlaybackTime]);
        }
        else {
            RETURN_FROM_LOAD_PROPERTIES(@"initialPlaybackTime", NUMINT(0));
        }
    }
    
    — answered October 2nd 2010 by James Low
    permalink
    0 Comments
  • Yay! setCurrentPlaybackTime is now supported in 3.1.1.GA!! Thank you Titanium devs. :) No more need for hacks. I am happy.

    — answered July 7th 2013 by Nick Robillard
    permalink
    2 Comments
    • Note: Just be sure to pass a millisecond value - not seconds.

      — commented July 7th 2013 by Nick Robillard
    • Hello Nick,

      Where do you find an example of this?

      Thanks.

      — commented July 22nd 2013 by Nicolai Villadsen
  • Dears

    for backward videoPlayer.setCurrentPlaybackTime($.videoPlayer.getCurrentPlaybackTime()-6000);
    for forward videoPlayer.setCurrentPlaybackTime($.videoPlayer.getCurrentPlaybackTime()-6000);

    please put ur time in milliseconds

    — answered September 10th 2013 by Muhammad Hamdy
    permalink
    0 Comments
  • Totally agree with you, this is a little implementation for great services…Go Go Titanium developper team ! :)

    — answered July 6th 2011 by Yoann WYFFELS
    permalink
    0 Comments
  • hi,

    when I use setcurrentPlaybackTime(15) it gives <null> value..why?

    — answered March 16th 2012 by Amol Jadhav
    permalink
    0 Comments
  • Does anyone have a solution for the above using sdk 2.0.1 as the above no longer seems to work?

    Thanks

    — answered May 23rd 2012 by Dan Orange
    permalink
    0 Comments
  • Up please

    — answered June 15th 2012 by Ethan Sebban
    permalink
    0 Comments
  • Is there anyone who can tell how to override this class. I couldn't find the location "/Library/Application Support/Titanium/mobilesdk/osx/17.1/iphone/Classes/TiMediaVideoPlayerProxy.m" I just can find it in my project's build destination and it's cleared whenever I build the project.

    — answered July 16th 2012 by Beraat Aldemir
    permalink
    0 Comments
  • Here is an updated setcurrentPlaybackTime obj-c function for TiMediaVideoPlayerProxy.m. This works with sdk 2.0.1.GA.

    -(void)setcurrentPlaybackTime:(id)time
    {
      ENSURE_UI_THREAD_1_ARG(time);
      if (movie != nil) {
        NSTimeInterval ourTime = [[time objectAtIndex:0] doubleValue];
        if (ourTime > 0) {
          [movie setCurrentPlaybackTime: ourTime];
        }
      }
    }
    
    — answered December 16th 2012 by Nick Robillard
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.