Video Player

47 views
Skip to first unread message

Philippe Fuentes

unread,
Sep 25, 2015, 1:16:38 PM9/25/15
to Cappuccino & Objective-J
Hi guys,

Does any of you use a video player with Cappuccino ?
I need to play some .mp4 (among other) and I didn't find a way to do it.

Would that be interesting to have a wrapper around jwplayer ? maybe it's easy to do (have no clue, I'm not into JS, that's why I chose Cappuccino basically :) ).

Thanks in advance for your help
Philippe.

Per Persson

unread,
Oct 7, 2015, 9:08:19 AM10/7/15
to Cappuccino & Objective-J
Hi Philippe,

I used this code in a WebRTC application a couple of years ago (4), don't know if it works as-is but maybe it can get you started.

Regards,
Per

@implementation StreamView : CPView
{
    id stream
;
   
DOMElement videoElement;
}

- (id)initWithFrame:(CGRect)aFrame
{
   
self = [super initWithFrame:aFrame];

   
if (self) {
        videoElement
= document.createElement("video");
       
// Careful here, this cannot go before creation of the video element!
       
// var defaultStream = [[CPBundle mainBundle] pathForResource:@"video1.mp4"];
       
// [self setStream:defaultStream];
       
var bounds = [self bounds];
        videoElement
.width = ""+CGRectGetWidth(bounds);
        videoElement
.height = ""+CGRectGetHeight(bounds);
        videoElement
.style.top = "0px";
        videoElement
.style.left = "0px";
        videoElement
.setAttribute("autoplay", "true");
       
// videoElement.setAttribute("loop", "true");
        videoElement
.poster = [[CPBundle mainBundle] pathForResource:@"nofeed.jpg"];

        _DOMElement
.appendChild(videoElement);
   
}
   
return self;
}

- (void)setStream:(id)aStream
{
   
if (stream === aStream)
       
return;
    stream
= aStream;
   
try {
        videoElement
.src = webkitURL.createObjectURL(stream);
   
} catch (e) {
        videoElement
.src = stream;
   
}
    videoElement
.setAttribute("autoplay", "true");
}

- (id)stream
{
   
return stream;
}
@end

Philippe Fuentes

unread,
Oct 7, 2015, 9:36:07 AM10/7/15
to Cappuccino & Objective-J
I also started doing something like it by creating a "video" tag element in a CPView.
But I did not use webkitURL.createObjectURL for the source, will have to check what it means.

However, I'll need to play mp4 and youtube video as well, this is why I was thinking about wrapping a more complete existing JS player. 
Will have my own playlist system used with the player. 

Thanks a lot for your answer Per :)
Reply all
Reply to author
Forward
0 new messages