将iPhone的webViewDidFinishLoad检测到流媒体音频文件的播放结束

时间:2021-11-24 20:55:36

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:

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

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?

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

1 个解决方案

#1


0  

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.

我不确定这是不是问题,但你不应该在委托方法中影响你的实例变量theWebView。我不知道将WebView更改为webView将解决您被解雇的委托问题,但这是我首先要看的地方。

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.

要回答您的原始问题,在收到Webview响应之后,不会在流连接结束时调用此委托。我也正在寻找一个钩子来完成一个流的解决方案。

#1


0  

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.

我不确定这是不是问题,但你不应该在委托方法中影响你的实例变量theWebView。我不知道将WebView更改为webView将解决您被解雇的委托问题,但这是我首先要看的地方。

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.

要回答您的原始问题,在收到Webview响应之后,不会在流连接结束时调用此委托。我也正在寻找一个钩子来完成一个流的解决方案。