Пример #1
0
/*
Init() is a wrapper around gst_init() and must be called before any
other gstreamer calls and is used to initialize everything necessary.

In addition to setting up gstreamer for usage, a pointer to a slice of
strings may be passed in to parse standard gst command line arguments.
args will be modified to remove any flags that were handled.
Alternatively, nil may be passed in to not perform any command line
parsing.
*/
func Init(args *[]string) {
	if args != nil {
		argc := C.int(len(*args))
		argv := make([]*C.char, argc)
		for i, arg := range *args {
			argv[i] = C.CString(arg)
		}
		C.gst_init((*C.int)(unsafe.Pointer(&argc)),
			(***C.char)(unsafe.Pointer(&argv)))
		unhandled := make([]string, argc)
		for i := 0; i < int(argc); i++ {
			unhandled[i] = C.GoString(argv[i])
			C.free(unsafe.Pointer(argv[i]))
		}
		*args = unhandled
	} else {
		C.gst_init(nil, nil)
	}
}
Пример #2
0
func main() {
	var loop *C.GMainLoop
	var s0 byte
	mdir := ""

	flag.StringVar(&mdir, "mdir", "", "mp3文件目录")
	flag.BoolVar(&g_isOutOfOrder, "rand", false, "是否乱序播放")
	flag.Parse()

	if mdir == "" {
		flag.PrintDefaults()
		return
	}
	g_list = list.New()
	g_wg = new(sync.WaitGroup)
	C.gst_init((*C.int)(unsafe.Pointer(nil)),
		(***C.char)(unsafe.Pointer(nil)))
	loop = C.g_main_loop_new((*C.GMainContext)(unsafe.Pointer(nil)),
		C.gboolean(0)) // 创建主循环,在执行 g_main_loop_run后正式开始循环

	if err := filepath.Walk(mdir, walkFunc); err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	g_wg.Add(1)
	s := make(chan byte)
	defer close(s)
	go mp3_play_process(s, loop)
LOOP0:
	for {
		fmt.Fscanf(os.Stdin, "%c\n", &s0)
		switch s0 {
		case 's':
			s <- s0
		case 'r':
			s <- s0
		case 'n':
			s <- s0
		case 'p':
			s <- s0
		case 'q':
			s <- s0
			break LOOP0
		case 'h':
			fmt.Print("'s' -> 暂停\n" +
				"'r' -> 继续\n" +
				"'n' -> 下一首\n" +
				"'p' -> 上一首\n" +
				"'q' -> 退出\n")
		}
		s0 = 0
	}
	g_wg.Wait()
}
Пример #3
0
func main() {
	var loop *C.GMainLoop
	var s0 byte
	mdir := ""
	mfile := ""
	style := ""

	flag.StringVar(&mdir, "dir", "", "mp3文件目录")
	flag.StringVar(&mfile, "file", "", "mp3文件")
	flag.StringVar(&style, "style", "order", "播放方式[顺序:order|乱序:shuffle|单曲:single|单曲循环:sloop|全部循环:aloop]")
	flag.Parse()

	switch style {
	case "shuffle":
		g_isOutOfOrder = true
		g_play_style = PLAY_STYLE_SHUFFLE

	case "order":
		g_play_style = PLAY_STYLE_ORDER
	case "single":
		g_play_style = PLAY_STYLE_SINGLE
	case "sloop":
		g_play_style = PLAY_STYLE_SLOOP
	case "aloop":
		g_play_style = PLAY_STYLE_ALOOP
	default:
		flag.PrintDefaults()
		return
	}
	g_list = list.New()
	if mfile != "" {
		p, err := filepath.Abs(mfile)
		if err != nil {
			fmt.Printf("Error: %v\n", err)
			return
		}
		C.gst_init((*C.int)(unsafe.Pointer(nil)),
			(***C.char)(unsafe.Pointer(nil)))
		loop = C.g_main_loop_new((*C.GMainContext)(unsafe.Pointer(nil)),
			C.gboolean(0)) // 创建主循环,在执行 g_main_loop_run后正式开始循环
		mfile = fmt.Sprintf("file://%s", p)
		g_list.PushBack(mfile)
		g_play_style = PLAY_STYLE_SINGLE
	} else {
		if mdir == "" {
			flag.PrintDefaults()
			return
		}
		if err := filepath.Walk(mdir, walkFunc); err != nil {
			fmt.Printf("Error: %v\n", err)
			return
		}
	}

	g_wg = new(sync.WaitGroup)
	C.gst_init((*C.int)(unsafe.Pointer(nil)),
		(***C.char)(unsafe.Pointer(nil)))
	loop = C.g_main_loop_new((*C.GMainContext)(unsafe.Pointer(nil)),
		C.gboolean(0)) // 创建主循环,在执行 g_main_loop_run后正式开始循环

	s := make(chan byte)
	defer close(s)
	go PlayProcess(s, loop)

	isQuit := false
	for !isQuit {
		fmt.Fscanf(os.Stdin, "%c\n", &s0)
		switch s0 {
		case 's':
			fallthrough
		case 'r':
			fallthrough
		case 'n':
			fallthrough
		case 'p':
			fallthrough
		case 't':
			fallthrough
		case '+':
			fallthrough
		case '-':
			s <- s0
		case 'q':
			s <- s0
			isQuit = true
		case 'h':
			fmt.Print("'s' -> 暂停\n" +
				"'r' -> 继续\n" +
				"'n' -> 下一首\n" +
				"'p' -> 上一首\n" +
				"'q' -> 退出\n")
		}
		s0 = 0
	}

	g_wg.Wait()

}
Пример #4
0
func init() {
	C.gst_init(nil, nil)
}