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

Use offsetms on media query #140

Open
avraham1 opened this issue Nov 9, 2022 · 5 comments
Open

Use offsetms on media query #140

avraham1 opened this issue Nov 9, 2022 · 5 comments

Comments

@avraham1
Copy link

avraham1 commented Nov 9, 2022

I want to play media to the client from a certain point in time. But I can't play media with offsetms.

func playLesson(ctx context.Context, h *ari.ChannelHandle, lessonKey string, offsetms string) { h.Play("", "sound:path/to/file?offsetms=" + offsetms) }

How do you do that?
Thanks in advance

@Ulexus
Copy link
Member

Ulexus commented Nov 9, 2022

It looks like we need to add support for something like PlayOptions; we don't expose that right now. It shouldn't be too disruptive to just tack a PlayOptions... to the end of the channel (and bridge) Play functions and interfaces.

@avraham1
Copy link
Author

Thank you.

Do you have an estimate of when you will be able to add it?

@Ulexus
Copy link
Member

Ulexus commented Nov 10, 2022

No, but PRs are always welcome.

@Ulexus
Copy link
Member

Ulexus commented Nov 10, 2022

Also we do offer consulting and programming services, if you wish.

@serfreeman1337
Copy link
Contributor

I'm sorry that I'm completely forgot about additional params in #142.
Before api get tagged, what about changing it from variadic function to interface instead ?

Play(key *Key, playbackID string, opts interface{}) (*PlaybackHandle, error)
type PlaybackOptions struct {
	// Media URIs to play.
	Media []string `json:"media"`

	// For sounds, selects language for sound.
	Lang string `json:"lang,omitempty"`

	// Number of milliseconds to skip before playing. Only applies to the first URI if multiple media URIs are specified.
	OffsetMs int `json:"offsetms,omitempty"`

	// Number of milliseconds to skip for forward/reverse operations.
	SkipMs int `json:"skipms,omitempty"`
}
// StagePlay stages a `Play` operation on the bridge
func (c *Channel) StagePlay(key *ari.Key, playbackID string, opts interface{}) (*ari.PlaybackHandle, error) {
	if playbackID == "" {
		playbackID = rid.New(rid.Playback)
	}

	resp := make(map[string]interface{})

	var req interface{}

	switch v := opts.(type) {
	case string:
		req = struct {
			Media string `json:"media"`
		}{
			Media: v,
		}
	case ari.PlaybackOptions:
		req = v
	}

	playbackKey := c.client.stamp(ari.NewKey(ari.PlaybackKey, playbackID))

	return ari.NewPlaybackHandle(playbackKey, c.client.Playback(), func(pb *ari.PlaybackHandle) error {
		return c.client.post("/channels/"+key.ID+"/play/"+playbackID, &resp, &req)
	}), nil
}

This way will keep backward compatibility with v5 api:

 // v5 api (will be still valid with v6)
h.Play("myPlaybackID", "sound:hello-world")

// v6 api
h.Play("myPlaybackID", ari.PlaybackOptions{
	Media: []string{"hello-world"}, 
	Lang: "en", 
	OffsetMs: 750,
})
h.Play("myPlaybackID", ari.PlaybackOptions{
	Media: []string{"sound:your", "sound:extension", "sound:number", "sound:is", "digits:123"}, 
})

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

3 participants