I am trying to play an HEVC(H.265) codec media url on AVPlayer. But the video is not showing. I didn't get any solution. How do I implement this in ios?
let videoURL = URL(string: "http://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8")
let avPlayer = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = avPlayer
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
Following your example I am able to play this content on a device (not simulator)
Pay attention also that I changed the URL from HTTP to HTTPS!
import UIKit
import AVFoundation
class ViewController: UIViewController {
let videoURL = URL(string: "https://bitmovin-a.akamaihd.net/content/dataset/multi-codec/hevc/stream_fmp4.m3u8")
let avPlayer = AVPlayer()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
let asset = AVAsset(url: videoURL!)
let playerItem = AVPlayerItem(asset: asset)
avPlayer.replaceCurrentItem(with: playerItem)
let avLayer = AVPlayerLayer(player: avPlayer)
avLayer.frame = view.bounds
view.layer.addSublayer(avLayer)
avPlayer.play()
}
}
NB:
The container format for HEVC video MUST be fMP4.
There are a few ways to deliver HEVC content to users:
HEVC in HLS using MPEG-2 Transport Stream chunks, which Apple doesn’t
support
HEVC in HLS using fMP4 segments, which is what Apple announced on
WWDC17 and our player supports
HEVC in MPEG-DASH using fMP4 segments
For reference:
WWDC17 – HEVC with HLS – Apple just announced a feature that we support out of the box
HLS Authoring Specification for Apple Devices
Related
I am attempting to play a video file from a youtube url. I have created the AVPlayer and linked the url to the player. The player opens when I click the button, but the video player just shows the file continuously loading. I have changed the App Transport Security Settings -> Allow Arbitrary Loads on the plist.
Heres the code:
#IBAction func playVideo(_ sender: Any) {
let movieId = "xLCn88bfW1o"
let path = URL(string: "https://www.youtube.com/watch?v=\(movieId)")
let video = AVPlayer(url: path!)
let videoPlayer = AVPlayerViewController()
videoPlayer.player = video
present(videoPlayer, animated: true, completion: {
video.play()
})
}
EDIT: I've also tried by using the URL for sharing the video; https://youtu.be/xLCn88bfW1o.
The url you are using is not the url to the video, it is the url to a webpage which has the video embedded. There are tools out there that can help you get the actual url of the video file.
For example: YoutubeDirectLinkExtractor
YoutubeDirectLinkExtractor allows you to obtain the direct link to a YouTube video, which you can easily use with AVPlayer. It uses type safety and optionals to guarantee that you won't crash while extracting the link no matter what. There are popular alternatives, which use more straightforward and risky approach, though:
Use extracted video link with AVPlayer:
let y = YoutubeDirectLinkExtractor()
y.extractInfo(for: .urlString("https://www.youtube.com/watch?v=HsQvAnCGxzY"), success: { info in
let player = AVPlayer(url: URL(string: info.highestQualityPlayableLink!)!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}) { error in
print(error)
}
You need to pass the video file's direct URL to AVPlayer (not a Youtube website URL)
For example:
let path = URL(string: "https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4")
I'm using MPMoviePlayerController to play avi formatted video files.
The audio works, but the video doesn't. Why is that?
MPMoviePlayerViewController only supports .mov, .mp4,.mpv, and .3gp and is deprecated.
From Apple's documentation:
The MPMoviePlayerViewController class is formally deprecated in iOS 9.
(The MPMoviePlayerController class is also formally deprecated.) To
play video content in iOS 9 and later, instead use the
AVPictureInPictureController or AVPlayerViewController class from the
AVKit framework, or the WKWebView class from WebKit.
You should use AVPlayerViewController:
import AVFoundation
import AVKit
let videoPath = "https://video.avi"
let videoURL = URL(string: videoPath)
let player = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
playerViewController.player?.play()
}
or just add AVPlayer in as a subview:
let videoURL = URL(string: videoPath)
let player = AVPlayer(url: videoURL!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
view.layer.addSublayer(playerLayer)
player.play()
it supports the following audio/video formats:
.mpeg, .mpeg-2-video, .avi, .aifc-audio, .aac-audio, .mpeg-4, .au-audio, .aiff-audio, .mp2, .3gpp2, .ac3-audio, .mp3, .mpeg-2-transport-stream, .3gpp, .mpeg-4-audio
I think you cannot play .avi file using MPMoviePlayerController in ios.
As .avi format contents are not possible to decode the video on a iOS device.
I am making a small website for video viewing as a project,
I need to be able to play a video using the local player of the phone, in Android i managed to find the solution:
intent://localhost/video.avi#Intent;action=android.intent.action.VIEW;scheme=http;type=video/mp4;end
This tells the Android OS to open this file using a media player, I need something like this for iOS.
I couldn't find anything on the internet about this, all other posts deal with making an actual application, I don't have access to an iPhone making this even harder to test and play around with it.
How can I do this for iPhone? if not possible are there alternatives?
Notice the code is a mere URL and needs absolutely no further implementations
There's URL Schemes provided by Apple to launch different native stuff via links.
try this: videos://"your video url here"
as an alternative: youtube://"youtube video url here"
About Apple iPhone URL schemes:
https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899-CH1-SW1
Building an iOS application you can use AVFoundation framework, it has AVPlayer (samples are in Swift):
let videoUrl = NSURL(string: "video url here")
let videoPlayer = AVPlayer(URL: videoUrl!)
let playerLayer = AVPlayerLayer(player: videoPlayer)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
you can also use AVPlayerViewController class for it:
let videoUrl = NSURL(string: "video url here")
let videoPlayer = AVPlayer(URL: videoUrl!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
if let player = playerViewController.player {
player.play()
}
}
or you can use a UIWebView to play video from a player within a web page:
let webview = UIWebView(frame: CGRect(x: 0, y: 0, width: 240, height: 375))
im trying to stream videos from google drive but its not working
this is my code
func playVideo () {
let url = NSURL(string: "https://drive.google.com/file/d/0B9XuPgWwSkzrdHN5WWUydjJScDg/preview")!
let player = AVPlayer(URL: url)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player?.play()
}
}
i get this when i start the function image here
i solved the problem by Decodeing the html from the link and take the steam link from it
you can see the code here : https://github.com/DevZaid/GDSLink
your link is to flash video, not to some video supported by AVPlayer.
I want to play YouTube videos from my tvOS application. I found to play URL videos by AVPlayer, but not getting to play YouTube videos since UIWebView is not supported on tvOS. I don't want to use any third party libraries.
You need to use YoutubeSourceParserKit to parse data that you receive from url. Then you will have the url and you will be able to play video with the following code (Swift 2 solution for tvOS 9):
Youtube.h264videosWithYoutubeURL(NSURL.init(string: "https://www.youtube.com/any-video-url")!)
{ (videoInfo, error) -> Void in
if let videoURLString = videoInfo?["url"] as? String,
videoTitle = videoInfo?["title"] as? String {
let videoURL = NSURL(string: videoURLString)
let player = AVPlayer(URL: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
}