5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebViewでYoutubeを再生中にバックグラウンドにするとどうなるか?

Last updated at Posted at 2019-03-22

実験内容

WebViewでYoutubeを再生中にバックグラウンドにするとどうなるか?

手順

  1. アプリのWebViewでYoutubeを再生する
  2. 端末のホームボタンを押す(アプリがバックグラウンドになる)
  3. ブラウザのYoutubeが停止するか?

期待値は、バックグラウンドで動画の再生が止まり、音もならない

結果

OS4系のみバックグラウンドでも動画は止まらず、音声が流れ続けた。
しかも電源を押して端末をスリーブ(画面OFF)にしても音が流れ続けた!

機種は Galaxy S3α

OS5以上はバックグラウンドにすると勝手に再生が止まった。

対応策

WebViewを実装ときは webView.onResume() webView.onPause() をちゃんと書こう!

こんな感じで


    override fun onResume() {
        super.onResume()
        webView.onResume()
    }

    override fun onPause() {
        super.onPause()
        webView.onPause()
    }

これを実装してOS4系で、Youtubeを再生してバックグラウンドにすると動画再生が止まり、音がならなくなった!

onResume/onPauseを実装しないとどうなるか?

Googleから「Youtbeの規約を守らなかった」とみなされ、Playストアからアプリが削除される。

WebViewで動画を表示するさいは気をつけましょう!

実験に使用したコード

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?