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)
}
Related
I am using Twitch player library for playing video but getting error on load. Have anyone idea what changes have come in June 2020 to make it functional ?
class TwitchVideoPlayerViewController: TwitchPlayerViewController {
/// `videosArray` holds the videos that will be cycled through.
private static let videosArray = ["v708953783", "v70878990"]
/// `nextStreamIndex` holds the index of the video that should be cycled to next.
private var nextVideoIndex = 0
#IBAction func nextButtonPress(_ sender: Any) {
let videoToPlay = TwitchVideoPlayerViewController.videosArray[nextVideoIndex]
nextVideoIndex = (nextVideoIndex + 1) % TwitchVideoPlayerViewController.videosArray.count
twitchPlayer.setVideo(to: videoToPlay, timestamp: 0)
}
}
Link:- https://github.com/Chris-Perkins/TwitchPlayer[![enter image description here]1]1
I am trying to develop a music player app with equaliser. I am using AVAudioEngine and attaching AVAudioPlayerNode but when I change the song the previous song is also playing with the current song. Changing multiple song, plays all the song simultaneously. previously I was using MPMediaItemPlayer but in that case I was not able to attach equaliser. I want my app to play one song at a time with equaliser.
self.AVaudioEngine = AVAudioEngine.init()
self.AVaudioPlayerNode = AVAudioPlayerNode.init()
self.AVaudioUnitEQ = AVAudioUnitEQ(numberOfBands: 10)
self.AVaudioEngine.attach(self.AVaudioPlayerNode)
self.AVaudioEngine.attach(self.AVaudioUnitEQ)
self.AVaudioPlayerNode.scheduleFile(self.AVaudioFile, at: nil, completionHandler: nil)
self.AVaudioEngine.connect(self.AVaudioPlayerNode, to: self.AVaudioUnitEQ, format: self.AVaudioFile.processingFormat)
self.AVaudioEngine.connect(self.AVaudioUnitEQ, to: self.AVaudioEngine.mainMixerNode, format: self.AVaudioFile.processingFormat)
if !self.AVaudioEngine.isRunning {
try! self.AVaudioEngine.start()
}
let sampleRate = self.AVaudioFile.processingFormat.sampleRate / 2
let format = self.AVaudioEngine.mainMixerNode.outputFormat(forBus: 0)
self.AVaudioEngine.mainMixerNode.installTap(onBus: 0, bufferSize: AVAudioFrameCount(sampleRate), format: format, block:{ (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
})
self.AVaudioPlayerNode.play()
Thanks in advance!
It`s your code to start playing AVaudioPlayerNode. But, where is your code to stop playing AVaudioPlayerNode?
Have you seen this?
I am trying to play a short musical note sequence with a default sine wave as sound inside a Swift Playground. At a later point I'd like to replace the sound with a Soundfont but at the moment I'd be happy with just producing some sound.
I want this to be a midi like sequence with direct control over the notes, not something purely audio based. The AudioToolbox seems to provide what I am looking for but I have troubles fully understanding its usage. Here's what I am currently trying
import AudioToolbox
// Creating the sequence
var sequence:MusicSequence = nil
var musicSequence = NewMusicSequence(&sequence)
// Creating a track
var track:MusicTrack = nil
var musicTrack = MusicSequenceNewTrack(sequence, &track)
// Adding notes
var time = MusicTimeStamp(1.0)
for index:UInt8 in 60...72 {
var note = MIDINoteMessage(channel: 0,
note: index,
velocity: 64,
releaseVelocity: 0,
duration: 1.0 )
musicTrack = MusicTrackNewMIDINoteEvent(track, time, ¬e)
time += 1
}
// Creating a player
var musicPlayer:MusicPlayer = nil
var player = NewMusicPlayer(&musicPlayer)
player = MusicPlayerSetSequence(musicPlayer, sequence)
player = MusicPlayerStart(musicPlayer)
As you can imagine, there's no sound playing. I appreciate any ideas on how to have that sound sequence playing aloud.
You have to enable the asynchronous mode for the Playground.
Add this at the top (Xcode 7, Swift 2):
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
and your sequence will play.
The same for Xcode 8 (Swift 3):
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
Working MIDI example in a Swift Playground
import PlaygroundSupport
import AudioToolbox
var sequence : MusicSequence? = nil
var musicSequence = NewMusicSequence(&sequence)
var track : MusicTrack? = nil
var musicTrack = MusicSequenceNewTrack(sequence!, &track)
// Adding notes
var time = MusicTimeStamp(1.0)
for index:UInt8 in 60...72 { // C4 to C5
var note = MIDINoteMessage(channel: 0,
note: index,
velocity: 64,
releaseVelocity: 0,
duration: 1.0 )
musicTrack = MusicTrackNewMIDINoteEvent(track!, time, ¬e)
time += 1
}
// Creating a player
var musicPlayer : MusicPlayer? = nil
var player = NewMusicPlayer(&musicPlayer)
player = MusicPlayerSetSequence(musicPlayer!, sequence)
player = MusicPlayerStart(musicPlayer!)
PlaygroundPage.current.needsIndefiniteExecution = true
Great MIDI reference page with a nice chart
I am currently working on HTTP Live streaming video with AVPlayerViewController / AVPlayer
i am play a video with .m38u file supported
It playing fine but my question is that can i have the data of video like i have set 4 type of resolution while genrating the .m38u file.. , i can varies the resoltion at my end point now the question is how to get the all values which i have setup at my endpoint. I am play this is in android also and using Track i am able to fetch all the video information but in ios how can i fetch all the details containing the video like its height , with, track,resolution supported by video etc..
I have search alot but could not get succeed..
Need help
Thanks in advance
Anita, I start I hope here is slice of code for playing a VIDEO..
self.command.text = "Loading VIDEO"
let videoURL = self.currentSlide.aURL
self.playerItem = AVPlayerItem(URL: videoURL)
self.player = AVPlayer(playerItem: self.playerItem)
self.playerLayer = AVPlayerLayer(player: self.player)
self.streamPlayer = AVPlayerViewController()
self.streamPlayer.player = self.player
self.streamPlayer.view.frame = CGRect(x: 128, y: 222, width: 512, height: 256)
let currentFM = self.streamPlayer.player?.currentItem?.asset
for blah in (currentFM?.metadata.enumerate())! {
print("blah \(blah)")
}
self.presentViewController(self.streamPlayer, animated: true)
self.streamPlayer.player!.play()
}
I added a little extra for showing meta data about the video... it printed...
blah (0, <AVMetadataItem: 0x15e7e4280, identifier=itsk/gsst, keySpace=itsk, key class = __NSCFNumber, key=gsst, commonKey=(null), extendedLanguageTag= (null), dataType=com.apple.metadata.datatype.UTF-8, time={INVALID}, duration= {INVALID}, startDate=(null), extras={
dataType = 1;
dataTypeNamespace = "com.apple.itunes";
}, value=0>)
blah (1, <AVMetadataItem: 0x15e7e1a50, identifier=itsk/gstd, keySpace=itsk, key class = __NSCFNumber, key=gstd, commonKey=(null), extendedLanguageTag=(null), dataType=com.apple.metadata.datatype.UTF-8, time={INVALID}, duration={INVALID}, startDate=(null), extras={
dataType = 1;
dataTypeNamespace = "com.apple.itunes";
}, value=222980>)
Hopefully it means a lot more to you than it does to me :) What your looking I think is classed/called metadata in Applespeak...
Take a look at this post too
Capture still image from AVCaptureSession in Swift
It describes how-to capture a frame of your video, once you have a frame you can take a closer look at its meta data and I suspect find out some of the details you seek.
let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
Are the commands to try and fetch that... let me know if you manage to succeed!
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)
}
}