Play control buttons aren't shown when playing youtube video from uiwebview - ios

I'm trying to play a YouTube video inside a UIWebView in Swift, when the video goes on full screen I get a message on the header and the playback buttons aren't shown, I tried everything and tried to use google's YTPlayerView but it is the same issue, please help me solving this issue.
here is the code:
let htmlString = "<html><body style='margin:0px;padding:0px;'><script
type='text/javascript' src='http://www.youtube.com/iframe_api'>
</script><script type='text/javascript'>function
onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:
{onReady:onPlayerReady}})}function onPlayerReady(a){}</script><iframe
id='playerId' type='text/html' width='\(UIScreen.mainScreen().bounds.width)' height='\(self.imageCollectionView.frame.height)' src='\(url!.description)?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'></body></html>"
cell.vedioWebPage.allowsInlineMediaPlayback = true
cell.vedioWebPage.mediaPlaybackRequiresUserAction = false
cell.vedioWebPage.loadHTMLString(htmlString, baseURL: NSBundle.mainBundle().resourceURL)
and here is a screenshot:

Related

Play Video From Instagram

recently I have see that one of my apps feature stopped working. The main problem is that, now, I can play instagram videos from an URL. This feature was working time ago, but I can not say how time is broken because I have noticed the problem now.
For example, I have this URL from Instagram:
https://embed.storiesig.net/aHR0cHM6Ly9zY29udGVudC1hdGwzLTIuY2RuaW5zdGFncmFtLmNvbS9vMS92L3QxNi9mMS9tMTcvQzQ0NjhFNDI4NTkwN0JCM0M3QkREQjFEQ0MzMTJCODhfdHJhbnNjb2RlX291dHB1dF9kYXNoaW5pdC5tcDQ/ZWZnPWV5SnhaVjluY205MWNITWlPaUpiWENKcFoxOTNaV0pmWkdWc2FYWmxjbmxmZG5SelgyOTBabHdpWFNJc0luWmxibU52WkdWZmRHRm5Jam9pZG5SelgzWnZaRjkxY214blpXNHVOekl3TG5OMGIzSjVMbVJsWm1GMWJIUWlmUSZfbmNfaHQ9c2NvbnRlbnQtYXRsMy0yLmNkbmluc3RhZ3JhbS5jb20mX25jX2NhdD0xMDUmdnM9MTc4NzE0ODIzOTk2MjExNTBfMzM4ODI0NTY4MiZfbmNfdnM9SEJrY0ZRSVlXR2xuWDNOMGIzSnBaWE5mY0dWeWJXRnVaVzUwWDNCeWIyUXZRelEwTmpoRk5ESTROVGt3TjBKQ00wTTNRa1JFUWpGRVEwTXpNVEpDT0RoZmRISmhibk5qYjJSbFgyOTFkSEIxZEY5a1lYTm9hVzVwZEM1dGNEUVZBQUxJQVFBb0FCZ0FHd0dJQjNWelpWOXZhV3dCTVJVQUFDYjBvdWpjbG8zRVB4VUNLQUpETXl3WFFCUUFBQUFBQUFBWUVtUmhjMmhmWW1GelpXeHBibVZmTVY5Mk1SRUFkZWdIQUElM0QlM0QmY2NiPTktNCZvZT02MUIzRURDRSZvaD05ZjIyMmE3NWYxZmE1ZmYzNDlhZGM4MWNhNzFhZjExNCZfbmNfc2lkPWJhYjYzOA==
If you open the URL in web browser (Safari, Chrome, etc...) you will see the video running.
But If I try to play the video from a AVPlayer like it used to work, the video is not played. My code for video playback is like this:
let videoUrl = story.videoUrl!
if (videoUrl.absoluteString.lengthOfBytes(using: .utf8) > 0) {
let player = AVPlayer(url: videoUrl)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
}
Where story.videoUrl is the URL of the example. If yo play the URL in a AVPlayer you will see nothing, so I don't know what is going on.

How to play custom index in JWPlayer Playlist?

I have tried load playlist(e.g. config.playlist = arrPlaylist) and it is working for me ,
but when i am trying to play customIndex from my playlist it plays from startIndex only
Note: I have also add (playerJW.playlistIndex = iCurrentPlaylistIndex)
but not working
Lets assume you have JWPlayerController and UITableView or UICollectionView below. ( Similar view like YouTube has )
var player: JWPlayerController!
So just load your no of video objects ( array ) in UITableView or UICollectionView.
On didSelectedIndix just apply player.stop and again set file and play.
config.file = "https://URL...."
player = JWPlayerController.init(config: config)
player.play()

WKWebView media controls title displays Url

Is it possible to change the iOS media controls (lock screen, command center media) title from the Url when playing a video from WKWebView?
I have tryied the following and cannot get Now Playing info to change:
DispatchQueue.main.async() {
var nowPlayingInfo = [String : Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = "Some title"
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
Using https://www.youtube.com/iframe_api onYouTubeIframeAPIReady I can get the title and send it back to the app, but the issue is getting the now applying controls to update the title from the video Url.
The MPNowPlayingInfoCenter displays the title of the webpage as title of the currently played audio/video.
Since the homepage title is never visible in the webview, you can freely change it via Javascript as soon as a new audio or video file is played:
document.title = "your title";
The new homepage title will now be displayed on your NowPlayingInfoCenter as currently playing audio/video.
Works great for me.
You could also do it inside the app code (Objective-C):
[webView evaluateJavaScript:#"document.title = \"your title\";" completionHandler:nil];

Play Live streaming video with 10 seconds prebuffer

I am working with an iOS application, in which I have to play the HTTP Live streaming video of file type '.m3u8'. So, I went through some tutorials and some how I've played HTTP live streaming videos in MPMoviePlayerController in iOS.
Now I want to prebuffer the video for 10 seconds in the background to play continue.Please help me with this. I'll be really very grateful to you.
Thanks in Advance.
Here's my code
var moviestreamPlayer : MPMoviePlayerController = MPMoviePlayerController(contentURL: NSURL(string:"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"))
movieStreamPlayer.view.frame = self.view.bounds
self.view.addSubview(movieStreamPlayer.view)
movieStreamPlayer.fullscreen = true
movieStreamPlayer.movieSourceType = MPMovieSourceType.Streaming
// Play the movie!
movieStreamPlayer.prepareToPlay()
movieStreamPlayer.controlStyle = MPMovieControlStyle.Embedded
if(movieStreamPlayer.isPreparedToPlay)
{
movieStreamPlayer.play()
}

Playing Avi video in swift based application

I'm trying to play a video of type avi in an application created in xcode written in swift.
The thing is all of the videos I have are in avi and I cannot afford time spent converting the videos right now. Is there a way to play the video in the provided Media player library?
the code I wrote plays the audio of the video only:
func playVideo() {
let path = NSBundle.mainBundle().pathForResource(symbol, ofType:"avi")
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.prepareToPlay()
player.scalingMode = .AspectFill
self.view.addSubview(player.view)
}
or maybe there's a way to convert a video when the function is called?
I,
following the documentation of the MPMediaPlayer :
For movie files, this typically means files with the extensions .mov, .mp4, .mpv, and .3gp
So, unfortunately, you can't use the MPMediaPlayer to read your avi video.
Thanks to VLC for iOs source code, you can re-use it to implement a custom player to read these files.

Resources