gpt4 book ai didi

IOS-询问用户在uiwebview媒体播放器中播放歌曲

转载 作者:行者123 更新时间:2023-11-28 19:56:59 24 4
gpt4 key购买 nike

如果我在 UIWebView 中单击 mp3 url,它会弹出媒体播放器以自动播放 mp3。但在这里我需要的只是要求用户确认在 UIWebview 媒体播放器中播放歌曲。是否可以访问 UIWebview 媒体播放器?如果是怎么办?请帮助我

最佳答案

是的,可以要求用户确认。

用户 UIWebView 委托(delegate)方法:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
self.URL = [request URL];
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
AVURLAsset* asset;

self.songURL = [NSString stringWithFormat:@"%@",self.URL];

//Check for supported song formatted
if([self.songURL hasSuffix:@".mp3"] ||
[self.songURL hasSuffix:@".wav"] ||
[self.songURL hasSuffix:@".aiff"] ||
[self.songURL hasSuffix:@".aac"] ||
[self.songURL hasSuffix:@".m4a"] ||
[self.songURL hasSuffix:@".m4p"] ||
[self.songURL hasSuffix:@".caf"])
{

asset = [[AVURLAsset alloc]initWithURL:self.URL options:nil];

if(asset != nil)
{
UIActionSheet *actSheet = [[UIActionSheet alloc]
initWithTitle:@"Songs"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Download"
otherButtonTitles:@"Listen Online", nil];
[actSheet showInView:self.view];
}
[asset release];
return NO;

}
}
return YES;
}

在 UIActionSheetDelegate 方法上:

-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
[self.webView loadRequest:[NSURLRequest requestWithURL:self.URL]];
}
}

关于IOS-询问用户在uiwebview媒体播放器中播放歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25929283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com