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
Related
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 using Xamarin to develop an iOS app. I need to be able to record the audio from AVSpeechUtterance to a file, or stream the audio buffer from internal audio to a method that will populate a byte array.
I've searched high and low on how to record internal audio (from text to speech api). I'm only able to use the internal microphone for recording, not the audio being played by app.
Currently using Xamarin's example for text to speech:
public void Speak (string text)
{
var speechSynthesizer = new AVSpeechSynthesizer ();
var speechUtterance = new AVSpeechUtterance (text) {
Rate = AVSpeechUtterance.MaximumSpeechRate/2,
Voice = AVSpeechSynthesisVoice.FromLanguage ("en-US"),
Volume = 0.5f,
PitchMultiplier = 1.0f
};
speechSynthesizer.SpeakUtterance (speechUtterance);
}
Hints/solution can be C#, Swift or Objective C. I just need to be pointed in the general right direction.
I am using an AVPlayer object to play a live stream of an MP3, just using an HTTP link.
As with normal live video playing in iOS, there is a button that you can press to skip to live.
Is it possible to do this with AVPlayer?
E.g I am listening live, pause, then after however long play again. It continues from where I left it. But what if I want to skip to live?
I had the same need and made this extension to AVPlayer:
extension AVPlayer {
func seekToLive() {
if let items = currentItem?.seekableTimeRanges, !items.isEmpty {
let range = items[items.count - 1]
let timeRange = range.timeRangeValue
let startSeconds = CMTimeGetSeconds(timeRange.start)
let durationSeconds = CMTimeGetSeconds(timeRange.duration)
seek(to: CMTimeMakeWithSeconds(startSeconds + durationSeconds, 1))
}
}
}
I'm trying to play midi but it's not working, I can play an mp3 but when I change the code to midi and build - there is no sound. (with "bassmidi" plugin).
my code:
NSString *fileName = #"1";
NSString *fileType = #"mid"; // mid
BASS_Init(-1, 44100, 0, 0, 0); // initialize output device
NSString *respath=[[NSBundle mainBundle]pathForResource:fileName ofType:fileType]; // get path of audio file
HSTREAM stream=BASS_MIDI_StreamCreateFile(0, [respath UTF8String], 0, 0, BASS_SAMPLE_LOOP, 1);
BASS_ChannelPlay(stream, FALSE); // play the stream
For those who would be interested in using the BASSMIDI player on iOS, we implemented an AUv3 Audio Unit wrapped around the bassmidi library.
The main advantage is that this audio unit can be inserted into a graph of audio nodes handled by the iOS Audio Engine (just like you would do with the AVAudioUnitSampler).
The code is available on a public repository:
https://github.com/newzik/BassMidiAudioUnit
Feel free to use it!
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)
}
}