开发者

Will iPhones webViewDidFinishLoad Detect End of Playback" of Streamed Audio File

开发者 https://www.devze.com 2023-02-13 01:25 出处:网络
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 tha开发者_高级运维t contains the mp3 file being play

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 tha开发者_高级运维t 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消