Search code examples
iosswiftuiwebviewswift3

IOS Swift UIWebView how can I show videos without enlarging the video


I have a UIWebView in my app and it auto-starts however when it auto-starts the video takes over the whole screen. I would like to change that behavior so that it keeps it's current dimension and starts to play. Essentially how facebook and Instagram have their videos they start playing but they keep their current dimensions which allows the users to keep scrolling . Right now I display my videos inside a TableView and this is my code

  cell.video_stream.loadHTMLString("<iframe  width= \" \ 
(cell.video_stream.frame.width) \" height= \" \
(cell.video_stream.frame.height)\"  src = \"\(fileUrl!)\"/>", baseURL: nil)

Then I give them these 2 properties so I can Auto-start them

video_stream.allowsInlineMediaPlayback = true
video_stream.mediaPlaybackRequiresUserAction = false

Any suggestions would be appreciated .


Solution

  • In the documentation for allowsInlineMediaPlayback it says:

    When adding a video element to a HTML document on the iPhone, you must also include the playsinline attribute

    You could try:

    cell.video_stream.loadHTMLString("<iframe  width= \" \ 
    (cell.video_stream.frame.width) \" height= \" \
    (cell.video_stream.frame.height)\"  src = \"\(fileUrl!)\" playsinline>", baseURL: nil)