ios:youtube 视频通过自定义按钮静音 [英] ios: youtube video mute through custom button

查看:33
本文介绍了ios:youtube 视频通过自定义按钮静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序包含一个带有自定义 UIButton 的视频来管理视频.通过使用 Youtube iFrame api,我设法在 UIWebView 中播放 youtube 视频并隐藏其所有默认控件(用于全屏、音量等).现在我想通过自定义按钮控制视频.我怎么做?- fullscreen UIButton:使视频全屏- 静音/取消静音按钮:将视频静音/取消静音

My application contains a video with custom UIButtons to manage the video. By using the Youtube iFrame api I have managed to play the youtube video in UIWebView and hide all its default controls(for fullscreen, volume, etc.). Now I want to control the video through custom buttons. How do i do that? - fullscreen UIButton: to make the video fullscreen - Mute/Unmute button: to mute/unmute the video

参考我的另一个问题中的屏幕:

refer the screen from my other question:

objective-c:播放视频删除默认的全屏等功能

我该如何解决这个问题?UIWebview 中的视频代码:

How do i solve this? Code for video in UIWebview:

 NSString *htmlString =@"<!DOCTYPE html><html> <body><div id=\"player\"></div><script>var tag = document.createElement('script');tag.src = \"https://www.youtube.com/iframe_api\";var firstScriptTag = document.getElementsByTagName('script')[0];firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);var player;function onYouTubeIframeAPIReady() {player = new YT.Player('player', {height: '196',width: '309',videoId: 'GOiIxqcbzyM',playerVars: {playsinline: 1, controls: 0}, events: {'onReady': onPlayerReady,'onStateChange': onPlayerStateChange}});}function onPlayerReady(event) {event.target.playVideo();}var done = false;function onPlayerStateChange(event) {if (event.data == YT.PlayerState.PLAYING && !done) {setTimeout(stopVideo, 6000);done = true;}}function stopVideo() {}</script></body></html>";
_webViewVideo.delegate = self;

static NSString *youTubeVideoHTML = @"<iframe webkit-playsinline width=\"309\" height=\"200\" src=\"https://www.youtube.com/embed/GOiIxqcbzyM?feature=player_detailpage&playsinline=1\" frameborder=\"0\"></iframe>";
[_webViewVideo loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] resourceURL]];

推荐答案

这个组合做视频隐藏控件

This combination does the video to hide controls

NSDictionary *playerVars = @{
                             @"controls" : @0,
                             @"playsinline" : @1,
                             @"autohide" : @1,
                             @"showinfo" : @0,
                             @"modestbranding" : @1,
                             @"rel":@0
                             };

要在按钮单击时使视频全屏,请尝试保存当前视频经过的时间,并通过更改 playerVars 以显示控件并以编程方式触发全屏按钮操作(视频全屏播放)和seek to 方法来播放过去时间的视频.

To make the video full screen on button click, try saving the current video elapsed time and by changing playerVars to show controls and trigger full screen button action programmatically(the video plays in full screen) and the seek to method to play the video from elapsed time.

对于静音/取消静音,请尝试以编程方式降低当前手机音量以静音并将其设置为取消静音

For mute/unmute , try reducing the current phone volume programmatically to mute and set it on unmute

我不认为苹果提供 api 来改变音量.只有用户可以使用硬件控件进行操作

i dont think apple provides the api to change the volume. only user can do it using the hardware controls

这篇关于ios:youtube 视频通过自定义按钮静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆