Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Sound #1340

Closed
paweldurga opened this issue Jul 22, 2023 · 5 comments
Closed

No Sound #1340

paweldurga opened this issue Jul 22, 2023 · 5 comments

Comments

@paweldurga
Copy link

paweldurga commented Jul 22, 2023

The browser opened by chromedp does not play the video with sound, but the browser opened by double-clicking has sound.

What versions are you running?

$ go list -m github.com/chromedp/chromedp
github.com/chromedp/chromedp v0.9.1
$ google-chrome --version
115.0.5790.102
$ go version
go version go1.20.2 darwin/arm64

What did you do? Include clear steps.

package main

import (
	"context"
	"log"

	"github.com/chromedp/chromedp"
)

func main() {
	options := []chromedp.ExecAllocatorOption{
		chromedp.Flag("headless", false),
		chromedp.UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"), // 设置User-Agent
	}
	options = append(chromedp.DefaultExecAllocatorOptions[:], options...)
	ctx, cancel := chromedp.NewExecAllocator(
		context.Background(),
		options...,
	)
	ctx, cancel = chromedp.NewContext(
		ctx,
		chromedp.WithLogf(log.Printf),
	)
	defer cancel()

	// 导航到指定的 URL
	err := chromedp.Run(ctx, chromedp.Navigate("https://www.youtube.com/watch?v=oNTZ63xrc60"))
	if err != nil {
		log.Fatal(err)
	}
	select {}
}

What did you expect to see?

This video has sound.

What did you see instead?

This video has no sound.

@paweldurga
Copy link
Author

paweldurga commented Jul 23, 2023

@ZekeLu i need your help :)

@ZekeLu
Copy link
Member

ZekeLu commented Jul 23, 2023

Hi. Try adding the following option:

chromedp.Flag("mute-audio", false)

See #845.

@aohanhongzhi
Copy link

you will know why from the source code

// DefaultExecAllocatorOptions are the ExecAllocator options used by NewContext
// if the given parent context doesn't have an allocator set up. Do not modify
// this global; instead, use NewExecAllocator. See [ExampleExecAllocator].
//
// [ExampleExecAllocator]: https://pkg.go.dev/github.com/chromedp/chromedp#example-ExecAllocator
var DefaultExecAllocatorOptions = [...]ExecAllocatorOption{
	NoFirstRun,
	NoDefaultBrowserCheck,
	Headless,

	// After Puppeteer's default behavior.
	Flag("disable-background-networking", true),
	Flag("enable-features", "NetworkService,NetworkServiceInProcess"),
	Flag("disable-background-timer-throttling", true),
	Flag("disable-backgrounding-occluded-windows", true),
	Flag("disable-breakpad", true),
	Flag("disable-client-side-phishing-detection", true),
	Flag("disable-default-apps", true),
	Flag("disable-dev-shm-usage", true),
	Flag("disable-extensions", true),
	Flag("disable-features", "site-per-process,Translate,BlinkGenPropertyTrees"),
	Flag("disable-hang-monitor", true),
	Flag("disable-ipc-flooding-protection", true),
	Flag("disable-popup-blocking", true),
	Flag("disable-prompt-on-repost", true),
	Flag("disable-renderer-backgrounding", true),
	Flag("disable-sync", true),
	Flag("force-color-profile", "srgb"),
	Flag("metrics-recording-only", true),
	Flag("safebrowsing-disable-auto-update", true),
	Flag("enable-automation", true),
	Flag("password-store", "basic"),
	Flag("use-mock-keychain", true),
}


// Headless is the command line option to run in headless mode. On top of
// setting the headless flag, it also hides scrollbars and mutes audio.
func Headless(a *ExecAllocator) {
	Flag("headless", true)(a)
	// Like in Puppeteer.
	Flag("hide-scrollbars", true)(a)
	Flag("mute-audio", true)(a)
}

point

	Flag("mute-audio", true)(a)

@mi1wei
Copy link

mi1wei commented Jul 25, 2023

thank you

@mi1wei
Copy link

mi1wei commented Jul 25, 2023

please close the issue

@ZekeLu ZekeLu closed this as completed Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants