bass_audioplayer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bass_audioplayer.gemspec +24 -0
- data/ext/bass_audioplayer/bass_handle.c +118 -0
- data/ext/bass_audioplayer/bass_handle.h +27 -0
- data/ext/bass_audioplayer/extconf.rb +13 -0
- data/ext/bass_audioplayer/soundplayer.c +79 -0
- data/lib/bass_audioplayer/events.rb +17 -0
- data/lib/bass_audioplayer/version.rb +3 -0
- data/lib/bass_audioplayer.rb +11 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f687f7661bc293f9c0fa3eaafc4b207c7e53a605
|
4
|
+
data.tar.gz: e346508cbd050f16d872685ffc8fd2e9827bead1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c116cc3c6dc4fbe6f7880c65e2d5ffd3bb00815fc8c475d2832f3bae510c30be11df84bfc04a38f29a8c5344287d743dc1505b0a652d4e468b66cb695646e689
|
7
|
+
data.tar.gz: 3e51df3414e58795a75f5bbafd4eb1bf6e121028b4a5211d5454cf5ae8457e42d152a4668b00f2fc97cb35b291c46878a5b5f65e0caf7978ccaa26cd4c8e254b
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Edgar Wang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# BassAudioplayer
|
2
|
+
|
3
|
+
Simple audio play library based on [BASS](http://www.un4seen.com).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bass_audioplayer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bass_audioplayer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'bass_audioplayer'
|
23
|
+
player = BASSAudioPlayer::SoundPlayer.new
|
24
|
+
player.play_file('1.mp3')
|
25
|
+
player.toggle
|
26
|
+
player.length
|
27
|
+
player.position
|
28
|
+
player.stop
|
29
|
+
player.play_url('http://example.com/1.mp3')
|
30
|
+
callback = Proc.new { puts 'DONE' }
|
31
|
+
player.register_end_callback(callback)
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/[my-github-username]/bass_audioplayer/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bass_audioplayer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bass_audioplayer"
|
8
|
+
spec.version = BASSAudioPlayer::VERSION
|
9
|
+
spec.authors = ["Edgar Wang"]
|
10
|
+
spec.email = ["edgar.xiaoxiangyu@gmail.com"]
|
11
|
+
spec.summary = %q{Simple audio player based on BASS}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.extensions << 'ext/bass_audioplayer/extconf.rb'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#include "bass_handle.h"
|
2
|
+
|
3
|
+
void raise_error()
|
4
|
+
{
|
5
|
+
rb_raise(rb_eStandardError,
|
6
|
+
"BASS error with error code %d", BASS_ErrorGetCode());
|
7
|
+
}
|
8
|
+
|
9
|
+
bass_handle* bass_handle_new()
|
10
|
+
{
|
11
|
+
bass_handle* handle = (bass_handle*)malloc(sizeof(bass_handle));
|
12
|
+
handle->stream = 0;
|
13
|
+
return handle;
|
14
|
+
}
|
15
|
+
|
16
|
+
void bass_handle_init(bass_handle* handle)
|
17
|
+
{
|
18
|
+
if (BASS_Init(-1, 44100, 0, 0, NULL) == FALSE) {
|
19
|
+
raise_error();
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
void bass_handle_cleanup(bass_handle* handle)
|
24
|
+
{
|
25
|
+
BASS_Free();
|
26
|
+
free(handle);
|
27
|
+
}
|
28
|
+
|
29
|
+
void bass_handle_stream_create_from_file(bass_handle* handle, const char* file)
|
30
|
+
{
|
31
|
+
handle->stream = BASS_StreamCreateFile(FALSE, file, 0, 0, 0);
|
32
|
+
if (handle->stream == 0) {
|
33
|
+
raise_error();
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
void bass_handle_stream_create_from_url(bass_handle* handle, const char* url)
|
38
|
+
{
|
39
|
+
handle->stream = BASS_StreamCreateURL(url, 0, 0, NULL, 0);
|
40
|
+
if (handle->stream == 0) {
|
41
|
+
raise_error();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
void bass_handle_stream_release(bass_handle* handle)
|
46
|
+
{
|
47
|
+
if (handle->stream != 0) {
|
48
|
+
BASS_StreamFree(handle->stream);
|
49
|
+
handle->stream = 0;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
void bass_handle_stream_play(bass_handle* handle)
|
54
|
+
{
|
55
|
+
if (BASS_ChannelPlay(handle->stream, FALSE) == FALSE) {
|
56
|
+
raise_error();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
void bass_handle_stream_stop(bass_handle* handle)
|
61
|
+
{
|
62
|
+
if (BASS_ChannelStop(handle->stream) == FALSE) {
|
63
|
+
raise_error();
|
64
|
+
}
|
65
|
+
bass_handle_stream_release(handle);
|
66
|
+
}
|
67
|
+
|
68
|
+
void bass_handle_stream_toggle(bass_handle* handle)
|
69
|
+
{
|
70
|
+
QWORD channel_status = BASS_ChannelIsActive(handle->stream);
|
71
|
+
if (channel_status == BASS_ACTIVE_PLAYING) {
|
72
|
+
if (BASS_ChannelPause(handle->stream) == FALSE) {
|
73
|
+
raise_error();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
if (channel_status == BASS_ACTIVE_PAUSED) {
|
78
|
+
bass_handle_stream_play(handle);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
double bass_handle_stream_length(bass_handle* handle)
|
83
|
+
{
|
84
|
+
QWORD len = BASS_ChannelGetLength(handle->stream, BASS_POS_BYTE);
|
85
|
+
double time = BASS_ChannelBytes2Seconds(handle->stream, len);
|
86
|
+
if (time < 0) {
|
87
|
+
raise_error();
|
88
|
+
}
|
89
|
+
|
90
|
+
return time;
|
91
|
+
}
|
92
|
+
|
93
|
+
double bass_handle_stream_position(bass_handle* handle)
|
94
|
+
{
|
95
|
+
QWORD pos = BASS_ChannelGetPosition(handle->stream, BASS_POS_BYTE);
|
96
|
+
double time = BASS_ChannelBytes2Seconds(handle->stream, pos);
|
97
|
+
if (time < 0) {
|
98
|
+
raise_error();
|
99
|
+
}
|
100
|
+
|
101
|
+
return time;
|
102
|
+
}
|
103
|
+
|
104
|
+
static void CALLBACK SYNC_END_CALLBACK(HSYNC handle, DWORD channel, DWORD data, void* userdata)
|
105
|
+
{
|
106
|
+
VALUE cb = (VALUE)userdata;
|
107
|
+
rb_funcall(cb, rb_intern("call"), 0);
|
108
|
+
}
|
109
|
+
|
110
|
+
void bass_handle_stream_register_end_callback(bass_handle* handle, VALUE cb)
|
111
|
+
{
|
112
|
+
if (rb_class_of(cb) != rb_cProc) {
|
113
|
+
rb_raise(rb_eTypeError, "Expected Proc callback");
|
114
|
+
}
|
115
|
+
|
116
|
+
BASS_ChannelSetSync(handle->stream, BASS_SYNC_END,
|
117
|
+
0, SYNC_END_CALLBACK, (void*)cb);
|
118
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef __BASS_HANDLE_H__
|
2
|
+
#define __BASS_HANDLE_H__
|
3
|
+
|
4
|
+
#include <ruby-2.1.0/ruby.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <bass.h>
|
7
|
+
|
8
|
+
typedef struct {
|
9
|
+
HSTREAM stream;
|
10
|
+
} bass_handle;
|
11
|
+
|
12
|
+
void raise_error();
|
13
|
+
|
14
|
+
bass_handle* bass_handle_new();
|
15
|
+
void bass_handle_init(bass_handle* handle);
|
16
|
+
void bass_handle_cleanup(bass_handle* handle);
|
17
|
+
void bass_handle_stream_create_from_file(bass_handle* handle, const char* file);
|
18
|
+
void bass_handle_stream_create_from_url(bass_handle* handle, const char* url);
|
19
|
+
void bass_handle_stream_release(bass_handle* handle);
|
20
|
+
void bass_handle_stream_play(bass_handle* handle);
|
21
|
+
void bass_handle_stream_stop(bass_handle* handle);
|
22
|
+
void bass_handle_stream_toggle(bass_handle* handle);
|
23
|
+
double bass_handle_stream_length(bass_handle* handle);
|
24
|
+
double bass_handle_stream_position(bass_handle* handle);
|
25
|
+
void bass_handle_stream_register_end_callback(bass_handle* handle, VALUE cb);
|
26
|
+
|
27
|
+
#endif // __BASS_HANDLE_H__
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#include "bass_handle.h"
|
2
|
+
|
3
|
+
VALUE rb_mBASSAudioPlayer;
|
4
|
+
VALUE rb_cSoundPlayer;
|
5
|
+
|
6
|
+
static VALUE rb_soundplayer_new(VALUE klass)
|
7
|
+
{
|
8
|
+
bass_handle* handle = bass_handle_new();
|
9
|
+
bass_handle_init(handle);
|
10
|
+
|
11
|
+
return Data_Wrap_Struct(rb_cSoundPlayer, 0,
|
12
|
+
bass_handle_cleanup, handle);
|
13
|
+
}
|
14
|
+
|
15
|
+
static VALUE rb_soundplayer_play_file(VALUE self, const VALUE file)
|
16
|
+
{
|
17
|
+
Check_Type(file, T_STRING);
|
18
|
+
bass_handle_stream_create_from_file(DATA_PTR(self), RSTRING_PTR(file));
|
19
|
+
bass_handle_stream_play(DATA_PTR(self));
|
20
|
+
return self;
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE rb_soundplayer_play_url(VALUE self, const VALUE url)
|
24
|
+
{
|
25
|
+
Check_Type(url, T_STRING);
|
26
|
+
bass_handle_stream_create_from_url(DATA_PTR(self), RSTRING_PTR(url));
|
27
|
+
bass_handle_stream_play(DATA_PTR(self));
|
28
|
+
return self;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rb_soundplayer_stop(VALUE self)
|
32
|
+
{
|
33
|
+
bass_handle_stream_stop(DATA_PTR(self));
|
34
|
+
return self;
|
35
|
+
}
|
36
|
+
|
37
|
+
static VALUE rb_soundplayer_toggle(VALUE self)
|
38
|
+
{
|
39
|
+
bass_handle_stream_toggle(DATA_PTR(self));
|
40
|
+
return self;
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE rb_soundplayer_length(VALUE self)
|
44
|
+
{
|
45
|
+
return rb_float_new(bass_handle_stream_length(DATA_PTR(self)));
|
46
|
+
}
|
47
|
+
|
48
|
+
static VALUE rb_soundplayer_position(VALUE self)
|
49
|
+
{
|
50
|
+
return rb_float_new(bass_handle_stream_position(DATA_PTR(self)));
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE rb_soundplayer_register_end_callback(VALUE self, VALUE cb)
|
54
|
+
{
|
55
|
+
bass_handle_stream_register_end_callback(DATA_PTR(self), cb);
|
56
|
+
return self;
|
57
|
+
}
|
58
|
+
|
59
|
+
void init_soundplayer(void)
|
60
|
+
{
|
61
|
+
rb_cSoundPlayer = rb_define_class_under(rb_mBASSAudioPlayer, "SoundPlayer", rb_cObject);
|
62
|
+
|
63
|
+
rb_define_singleton_method(rb_cSoundPlayer, "new", rb_soundplayer_new, 0);
|
64
|
+
rb_define_method(rb_cSoundPlayer, "play_file", rb_soundplayer_play_file, 1);
|
65
|
+
rb_define_method(rb_cSoundPlayer, "play_url", rb_soundplayer_play_url, 1);
|
66
|
+
rb_define_method(rb_cSoundPlayer, "stop", rb_soundplayer_stop, 0);
|
67
|
+
rb_define_method(rb_cSoundPlayer, "toggle", rb_soundplayer_toggle, 0);
|
68
|
+
rb_define_method(rb_cSoundPlayer, "length", rb_soundplayer_length, 0);
|
69
|
+
rb_define_method(rb_cSoundPlayer, "position", rb_soundplayer_position, 0);
|
70
|
+
rb_define_method(rb_cSoundPlayer, "register_end_callback",
|
71
|
+
rb_soundplayer_register_end_callback, 1);
|
72
|
+
}
|
73
|
+
|
74
|
+
void Init_bass_audioplayer(void)
|
75
|
+
{
|
76
|
+
rb_mBASSAudioPlayer = rb_define_module("BASSAudioPlayer");
|
77
|
+
|
78
|
+
init_soundplayer();
|
79
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BASSAudioPlayer
|
2
|
+
class Events
|
3
|
+
def initialize
|
4
|
+
@handlers = Hash.new { |h, k| h[k] = [] }
|
5
|
+
end
|
6
|
+
|
7
|
+
def on(event, &block)
|
8
|
+
@handlers[event] << block
|
9
|
+
end
|
10
|
+
|
11
|
+
def trigger(event, *args)
|
12
|
+
@handlers[event].each do |handler|
|
13
|
+
handler.call(*args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bass_audioplayer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edgar Wang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- edgar.xiaoxiangyu@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/bass_audioplayer/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bass_audioplayer.gemspec
|
55
|
+
- ext/bass_audioplayer/bass_handle.c
|
56
|
+
- ext/bass_audioplayer/bass_handle.h
|
57
|
+
- ext/bass_audioplayer/extconf.rb
|
58
|
+
- ext/bass_audioplayer/soundplayer.c
|
59
|
+
- lib/bass_audioplayer.rb
|
60
|
+
- lib/bass_audioplayer/events.rb
|
61
|
+
- lib/bass_audioplayer/version.rb
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.2.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Simple audio player based on BASS
|
86
|
+
test_files: []
|