Video in UIView ?

Discussion in 'iOS Programming' started by ifreeman, Mar 20, 2011.

  1. ifreeman macrumors newbie

    Joined:
    Mar 3, 2011
    #1
    Hi,


    I would like to know if I can play a video in UIView?


    I want to play a video in a small UIView (say 100 x 100 ) which should be played automatically when the UIView loads

    First I would say what I tried out ... It would be really helpful if the experts ( I am a 2 week old baby in IOS development & Obj- C) to confirm whether the route i am heading is right..


    I created a UIWebView and and tried to embed a video in it using HTML video tag (html5)
    For the UIWebview i set the allowInlineMediaPlayback to YES and mediaPlaybackRequiresUserAction to NO ... also in the HTML code, for the video tag, i used - webkit-playsinline


    any help is much appreciated
     
  2. ifreeman thread starter macrumors newbie

    Joined:
    Mar 3, 2011
    #2


    and here is the piece of code that i'm using -


    NSString *embedHTML = @"\
    <!DOCTYPE HTML>\
    <html>\
    <head>\
    <script type=\"text/javascript\">\
    function playvideo() {\
    var myVideo=document.getElementsByTagName('video')[0];\
    myVideo.play();\
    myVideo.webkitExitFullscreen();\
    myVideo.height = 120;\
    myVideo.width = 120;\
    }\
    </script>\
    </head>\
    <body onLoad = \"playvideo()\" >\
    <video id=\"player\" webkit-playsinline width=\"140\" height=\"140\">\
    <source src=\"file:///Users/Shilpa/Desktop/Movie Player/MoviePlayer-ios4-Next/Movie-1.mp4\"/>\
    </video>\
    </body>\
    </html>";

    webView = [[UIWebView alloc] initWithFrame:CGRectMake(100.0, 170.0, 150.0, 150.0)];
    [webView setOpaque:YES];

    NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
    [webView loadHTMLString:html baseURL:nil];
    webView.allowsInlineMediaPlayback = YES;
    webView.mediaPlaybackRequiresUserAction = NO;

    webView.transform = CGAffineTransformMakeRotation(3.14/2);

    [moviePlayerWindow addSubview:webView];
     
  3. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    U could also use the standard MPMoviePlayer build in? drag your resources to your project, and badem, works! x)
     
  4. ifreeman thread starter macrumors newbie

    Joined:
    Mar 3, 2011
    #4
    Hi Jnoxx,

    Thanks for posting .... but I am very much new to iOS and obj-c development ... can you please post it in a little more detailed way for me to understand ....


    Basically, i want to play two videos simultaneously ... 1 video in full screen, another video in a small box (UIView or WebView) on top of first video (to be started after few seconds of first video playback)....

    I tried to create two instance for MPMoviePlayer ... but when I initialize memory for the second player .... the video playing in the first player is stopped ..... is it a single-ton?

    due to this reason, I used UIWebview for the second video playback .....


    In summary - this is my issue -

    What I need:

    2 videos - video A - full screen ... video B small size on top of video A (playback of video B to astart after 10 secs of Video A)


    What I get:

    As of now - Video A plays in full screen ... after 10 seconds , video B starts, but in full screen mode (i do not want that)


    Thanks.
     
  5. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    I don't think that's possible from the HIG. That 2 video's play on top of each other, u can do multiple video's, in 1 view, since the 4.2 I think. But, not on top of each other, think google is your friend in that case :)
     
  6. ifreeman thread starter macrumors newbie

    Joined:
    Mar 3, 2011
    #6


    hmmm .... if thats the case , then :( .... thanks (anyway) Jnoxx ! :)

    But i was thinking the case of iAD - though i do not have much knowledge about iAD - I know that iAD is used for mobile advertising in iOS....

    so my question is , " does iAD support video ads ? "

    if it does, then there should be a use case where we run the video ad over some custom developed media player/native player - playing video/ live streaming


    isnt that case similar to mine??


    so for the feasibility part of my requirement - i need to look more closely into how iAD is functioning ....

    if any of u guys have any exp in iAdsection plz help me in .... in the mean time i shall also do my part of research ....


    thanks all
     

Share This Page