iPhone 的 webViewDidFinishLoad 会检测到播放结束吗?流式音频文件的数量

发布于 2024-10-19 05:37:35 字数 923 浏览 6 评论 0原文

我正在尝试检测播客流的播放结束。我正在使用 loadRequest:[NSURLRequest requestWithURL:location] 加载包含正在播放的 mp3 文件的网页。在查看了问题档案后,我认为也许 协议的实现,特别是 webViewDidFinishLoad 方法的实现可能就是答案。但是,在实现它之后,我没有看到音频文件完成时调用此方法。事实上,我从未见过该方法被调用,这让我相信我可能没有正确实现它。这是我所做的:

在头文件中,我有:

@interface MyWebViewController : UIViewController<UIWebViewDelegate> {
    NSURL *location;    // holds the web address that will be loaded by this app
    IBOutlet UIWebView *theWebView;
}

在类实现文件中,我有:

- (void)viewDidLoad {
    [super viewDidLoad];

    theWebView.delegate = self;

    [theWebView loadRequest:[NSURLRequest requestWithURL:location]];
}

- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
    NSLog(@"view did finish");
}

这是确定加载到网页中的音频文件的播放结束的正确解决方案吗?如果没有,检测播放结束的更好方法是什么?如果这个解决方案背后的想法是正确的,那么我在这个实现中做错了什么?

I am trying to detect the end of playback of a podcast stream. I am using a loadRequest:[NSURLRequest requestWithURL:location] to load the web page that contains the mp3 file being played back. After looking through the archives of questions, I thought that maybe the implementation of the <UIWebViewDelegate> protocol and specifically the method webViewDidFinishLoad might be the answer. However, after implementing it, I am not seeing this method get called when the audio file finishes. In fact I never see the method get called, leading me to believe I may not have implemented it correctly. Here is what I did:

In the header file I have:

@interface MyWebViewController : UIViewController<UIWebViewDelegate> {
    NSURL *location;    // holds the web address that will be loaded by this app
    IBOutlet UIWebView *theWebView;
}

In the class implementation file I have:

- (void)viewDidLoad {
    [super viewDidLoad];

    theWebView.delegate = self;

    [theWebView loadRequest:[NSURLRequest requestWithURL:location]];
}

- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
    NSLog(@"view did finish");
}

Is this proper solution for determining the end of playback of an audio file that is loaded into a web page? If not, what would be a better way to detect the end of playback? If the idea behind this solution is correct, what did I do wrong with this implementation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事风中埋 2024-10-26 05:37:35

我不确定这是否是问题所在,但您不应该在委托方法中隐藏实例变量 theWebView 。我不知道将 WebView 更改为 webView 是否会解决委托被解雇的问题,但这就是我首先要考虑的地方。

为了回答您原来的问题,该委托在收到 Webview 响应后而不是在流连接结束时被调用。我还在寻找一种解决方案,用于挂钩流的完成。

I am not sure if this is the problem or not, but you should not shadow your instance variable theWebView within the delegate method. I don't know that changing theWebView to webView is going to solve your problem of the delegate being fired but that is where I would look first.

To answer your original question, this delegate gets called after the Webview response is received not at the end of a streaming connection. I am also looking into a solution for a hook into the completion of a stream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文