I have embedded videos (pulled from YouTube API v3) into my iPhone app using a UIWebView as suggested. The problem is that some videos, such as those from VEVO, produce the following error when attempting to play them on the device.
This video contains content from VEVO. It is restricted from playback on certain sites.
This should not occur, since apps like Flipboard and Rockpack also seem to be using a UIWebView, and are able to play videos from VEVO and other sources.
What could I be doing wrong?
PS: I am aware that there exist other posts that touch upon this issue in some way, but they fail to address this specific problem.
Using YouTube's YTPlayerView for iOS and setting the origin property to a valid URL allows many VEVO videos to be played properly.
In your View Controller:
#property (weak, nonatomic) IBOutlet YTPlayerView *playerView;
// ..
NSDictionary *playerVars = #{
#"playsinline" : #1,
#"showinfo" : #0,
#"rel" : #0,
#"controls" : #1,
#"origin" : #"https://www.example.com", // this is critical
#"modestbranding" : #1
};
[self.playerView loadWithVideoId:#"Ri7-vnrJD3k" playerVars:playerVars];
With origin:
Without origin:
Are you getting the error on all videos from VEVO?
Are you sure the video you're trying to play is embeddable?
Add the 'videoEmbeddable' parameter with the 'true' value so you're only working with videos you can embed.
The videoEmbeddable parameter lets you to restrict a search to only
videos that can be embedded into a webpage. If you specify a value for
this parameter, you must also set the type parameter's value to video.
Acceptable values are: any – Return all videos, embeddable or not.
true – Only retrieve embeddable videos.
source: https://developers.google.com/youtube/v3/docs/search/list#videoEmbeddable
For Swift 4.2 of #JAL's answer you just need to do the following and it will work like a charm with vevo videos:
import UIKit
import youtube_ios_player_helper
class MyYoutubePlayerViewController: UIViewController {
#IBOutlet weak var playerView: YTPlayerView!
private var playerVars: [String : Any] = [
"playsinline" : 1,
"showinfo" : 1,
"rel" : 1,
"modestbranding" : 1,
"controls" : 1,
"origin" : "https://www.youtube.com" ]
override func viewDidLoad() {
super.viewDidLoad()
self.playerView.load(withVideoId: "YQHsXMglC9A", playerVars: playerVars)
}
}
Related
First, this is a Youtube link showing the problem: Video stretched. The Youtube video is edited to remove unnecessary parts, I am only showing the important parts. As you can see after some time the video gets stretched.
The original video was uploaded to Azure media services and encoded by Azure media using the built-in "AdaptiveStreaming" preset.
I am using HLS dynamic packaging with this url:
https://amswrdev-usso.streaming.media.azure.net/80a2651c-462f-487f-b1a3-87cb72366255/1zIHQ.ism/manifest(format=m3u8-cmaf)
I am testing it on an Iphone 12 pro max, IOS 15.0.1, swift 5.0
I am using the AVPlayerViewController, this is the code:
import Foundation
import SwiftUI
import AVKit
struct VideoPlayerView: UIViewControllerRepresentable {
var player: AVPlayer
#Binding var gravity: AVLayerVideoGravity
func makeUIViewController(context: UIViewControllerRepresentableContext<VideoPlayerView>) -> AVPlayerViewController {
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = false
controller.videoGravity = gravity
return controller
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: UIViewControllerRepresentableContext<VideoPlayerView>) {
uiViewController.videoGravity = gravity
}
func dismantleUIViewController(_ uiViewController: AVPlayerViewController, coordinator: Self.Coordinator) {
//print("dismantleUIViewController \(uiViewController)")
}
}
My hypothesis:
Avplayer is not correctly switching to the correct bandwidth
Azure media is not sending the correct variants on the initial playlist
Maybe I don't have the correct parameters for preferredMaximumResolution and preferredForwardBufferDuration? but I don't know what values should be correct.
Dynamic packaging of azure media is now on version 7, maybe is not supported by IOS?
I have been trying to fix it changing my view to have fixed values of height and width but is not working. I have 2 weeks trying to figure out this but nothing is working, Do you have any idea?
Like I said the video is stretched after some time, is not consistent. Sometimes happens immediately and sometimes takes more time but happens.
I'm still on iOS 14 on an iPhone 8 - and it plays just fine for me... so this may be an iOS 15.0.1 issue right now.
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()
i am trying to play Youtube videos on my app. I am using YTPlayerView library for playing a video by video id. Problem is when i am trying to play a list of videos player showing an error that "An error occurred. Please try again later. (Playback ID: someid)".
I am using the following code for playing a single video
#IBOutlet weak var playerView: YTPlayerView! // story board connection
let params = ["controls" : 2, "playsinline" : 1, "autohide" :1, "showinfo" : 0, "modestbranding" : 0, "cc_load_policy" : 0, "rel" : 1] //,
playerView.delegate = self
playerView.loadWithVideoId("v_I0rA72IJE", playerVars:params)
Its working fine for a single video. But when i try to load a list of videos by using the following code i am getting that error.
playerView.loadWithPlayerParams(params)
playerView.loadPlaylistByVideos(["v_I0rA72IJE","l-ujrOIL-9M","yw002vpbClA"], index: 0, startSeconds: 0, suggestedQuality: YTPlaybackQuality.Default)
or
playerView.cuePlaylistByVideos(["v_I0rA72IJE","l-ujrOIL-9M","yw002vpbClA"], index: 0, startSeconds: 0, suggestedQuality: YTPlaybackQuality.Default)
Please help me to solve the issue. Please correct me if i am doing anything wrong.
Not an exact solution, but we can proceed for now
First load a single video
youtubePlayerView.loadWithVideoId(videoId, playerVars: params)
inside the playerViewDidBecomeReady(playerView: YTPlayerView) delegate method load that playlist
func playerViewDidBecomeReady(playerView: YTPlayerView)
{
playerView.cuePlaylistByVideos(videoIdsArray, index: 0, startSeconds: 0, suggestedQuality: YTPlaybackQuality.Default)
}
UIWebview get event when video is Played. I am playing youtube video in UIWebview. Is it possible to get event when a video is played in UIWebview
From Documentation https://developers.google.com/youtube/js_api_reference :
you could define some states in your header file
typedef NS_ENUM(NSInteger, YoutubeVideoState){
YOUTUBE_VIDEO_STATE_UNSTARTED = -1,
YOUTUBE_VIDEO_STATE_ENDED = 0,
YOUTUBE_VIDEO_STATE_PLAYING = 1,
YOUTUBE_VIDEO_STATE_PAUSED = 2,
YOUTUBE_VIDEO_STATE_BUFFERING = 3,
YOUTUBE_VIDEO_STATE_VIDEO_CUED = 5
};
Again define random property in header file to get the state.
#property (nonatomic, readonly) YoutubeVideoState state;
and implement like :
- (YoutubeVideoState)state
{
return (YoutubeVideoState)[[self.webView stringByEvaluatingJavaScriptFromString:#"getPlayerState()"] integerValue];
}
Then do like this:
if(event.data==YT.PlayerState.PLAYING){
//do here what do you want
}
Google has provide a library to embedding you tube into iOS.
https://developers.google.com/youtube/v3/guides/ios_youtube_helper
I am using AVFoundation to record a video and then upload to a server, and use AVPlayer to streaming it to play, but always get these 2 error notifications, is there any thing wrong in my output settings
NSDictionary *settings = #{AVVideoCodecKey : AVVideoCodecH264,
AVVideoWidthKey : #(480),
AVVideoHeightKey : #(480),
AVVideoScalingModeKey : AVVideoScalingModeResizeAspectFill,
AVVideoCompressionPropertiesKey:#{
AVVideoAverageBitRateKey : #(480*480*11.4),
AVVideoMaxKeyFrameIntervalKey : #(24)
}
};
But I can play it very well with AVPlayer locally (means in iPhone)